<html lang="en">
<head>
<title>Comparing and Merging Files</title>
<meta http-equiv="Content-Type" content="text/html">
<meta name="description" content="Comparing and Merging Files">
<meta name="generator" content="makeinfo 4.8">
<link title="Top" rel="top" href="#Top">
<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
<!--
This manual is for GNU Diffutils
(version 2.8.1, 5 April 2002),
and documents the GNU `diff', `diff3',
`sdiff', and `cmp' commands for showing the
differences between files and the GNU `patch' command for
using their output to update files.

Copyright (C) 1992, 1993, 1994, 1998, 2001, 2002 Free
Software Foundation, Inc.

     Permission is granted to copy, distribute and/or modify this
     document under the terms of the GNU Free Documentation License,
     Version 1.1 or any later version published by the Free Software
     Foundation; with no Invariant Sections, with the Front-Cover texts
     being "A GNU Manual," and with the Back-Cover Texts as in (a)
     below.  A copy of the license is included in the section entitled
     "GNU Free Documentation License."

     (a) The FSF's Back-Cover Text is: "You have freedom to copy and
     modify this GNU Manual, like GNU software.  Copies published by
     the Free Software Foundation raise funds for GNU development."
   -->
<meta http-equiv="Content-Style-Type" content="text/css">
<style type="text/css"><!--
  pre.display { font-family:inherit }
  pre.format  { font-family:inherit }
  pre.smalldisplay { font-family:inherit; font-size:smaller }
  pre.smallformat  { font-family:inherit; font-size:smaller }
  pre.smallexample { font-size:smaller }
  pre.smalllisp    { font-size:smaller }
  span.sc    { font-variant:small-caps }
  span.roman { font-family:serif; font-weight:normal; } 
  span.sansserif { font-family:sans-serif; font-weight:normal; } 
--></style>
</head>
<body>
<h1 class="settitle">Comparing and Merging Files</h1>
   <div class="shortcontents">
<h2>Short Contents</h2>
<ul>
<li><a href="#toc_Top">Comparing and Merging Files</a></li>
<li><a href="#toc_Overview">Overview</a></li>
<li><a href="#toc_Comparison">1 What Comparison Means</a></li>
<li><a href="#toc_Output-Formats">2 <samp><span class="command">diff</span></samp> Output Formats</a></li>
<li><a href="#toc_Incomplete-Lines">3 Incomplete Lines</a></li>
<li><a href="#toc_Comparing-Directories">4 Comparing Directories</a></li>
<li><a href="#toc_Adjusting-Output">5 Making <samp><span class="command">diff</span></samp> Output Prettier</a></li>
<li><a href="#toc_diff-Performance">6 <samp><span class="command">diff</span></samp> Performance Tradeoffs</a></li>
<li><a href="#toc_Comparing-Three-Files">7 Comparing Three Files</a></li>
<li><a href="#toc_diff3-Merging">8 Merging From a Common Ancestor</a></li>
<li><a href="#toc_Interactive-Merging">9 Interactive Merging with <samp><span class="command">sdiff</span></samp></a></li>
<li><a href="#toc_Merging-with-patch">10 Merging with <samp><span class="command">patch</span></samp></a></li>
<li><a href="#toc_Making-Patches">11 Tips for Making and Using Patches</a></li>
<li><a href="#toc_Invoking-cmp">12 Invoking <samp><span class="command">cmp</span></samp></a></li>
<li><a href="#toc_Invoking-diff">13 Invoking <samp><span class="command">diff</span></samp></a></li>
<li><a href="#toc_Invoking-diff3">14 Invoking <samp><span class="command">diff3</span></samp></a></li>
<li><a href="#toc_Invoking-patch">15 Invoking <samp><span class="command">patch</span></samp></a></li>
<li><a href="#toc_Invoking-sdiff">16 Invoking <samp><span class="command">sdiff</span></samp></a></li>
<li><a href="#toc_Standards-conformance">17 Standards conformance</a></li>
<li><a href="#toc_Projects">18 Future Projects</a></li>
<li><a href="#toc_Copying-This-Manual">Appendix A Copying This Manual</a></li>
<li><a href="#toc_Index">Appendix B Index</a></li>
</ul>
</div>



   <div class="contents">
<h2>Table of Contents</h2>
<ul>
<li><a name="toc_Top" href="#Top">Comparing and Merging Files</a>
<li><a name="toc_Overview" href="#Overview">Overview</a>
<li><a name="toc_Comparison" href="#Comparison">1 What Comparison Means</a>
<ul>
<li><a href="#Hunks">1.1 Hunks</a>
<li><a href="#White-Space">1.2 Suppressing Differences in Blank and Tab Spacing</a>
<li><a href="#Blank-Lines">1.3 Suppressing Differences in Blank Lines</a>
<li><a href="#Case-Folding">1.4 Suppressing Case Differences</a>
<li><a href="#Specified-Folding">1.5 Suppressing Lines Matching a Regular Expression</a>
<li><a href="#Brief">1.6 Summarizing Which Files Differ</a>
<li><a href="#Binary">1.7 Binary Files and Forcing Text Comparisons</a>
</li></ul>
<li><a name="toc_Output-Formats" href="#Output-Formats">2 <samp><span class="command">diff</span></samp> Output Formats</a>
<ul>
<li><a href="#Sample-diff-Input">2.1 Two Sample Input Files</a>
<li><a href="#Normal">2.2 Showing Differences Without Context</a>
<ul>
<li><a href="#Detailed-Normal">2.2.1 Detailed Description of Normal Format</a>
<li><a href="#Example-Normal">2.2.2 An Example of Normal Format</a>
</li></ul>
<li><a href="#Context">2.3 Showing Differences in Their Context</a>
<ul>
<li><a href="#Context-Format">2.3.1 Context Format</a>
<ul>
<li><a href="#Detailed-Context">2.3.1.1 Detailed Description of Context Format</a>
<li><a href="#Example-Context">2.3.1.2 An Example of Context Format</a>
<li><a href="#Less-Context">2.3.1.3 An Example of Context Format with Less Context</a>
</li></ul>
<li><a href="#Unified-Format">2.3.2 Unified Format</a>
<ul>
<li><a href="#Detailed-Unified">2.3.2.1 Detailed Description of Unified Format</a>
<li><a href="#Example-Unified">2.3.2.2 An Example of Unified Format</a>
</li></ul>
<li><a href="#Sections">2.3.3 Showing Which Sections Differences Are in</a>
<ul>
<li><a href="#Specified-Headings">2.3.3.1 Showing Lines That Match Regular Expressions</a>
<li><a href="#C-Function-Headings">2.3.3.2 Showing C Function Headings</a>
</li></ul>
<li><a href="#Alternate-Names">2.3.4 Showing Alternate File Names</a>
</li></ul>
<li><a href="#Side-by-Side">2.4 Showing Differences Side by Side</a>
<ul>
<li><a href="#Side-by-Side-Format">2.4.1 Controlling Side by Side Format</a>
<li><a href="#Example-Side-by-Side">2.4.2 An Example of Side by Side Format</a>
</li></ul>
<li><a href="#Scripts">2.5 Making Edit Scripts</a>
<ul>
<li><a href="#ed-Scripts">2.5.1 <samp><span class="command">ed</span></samp> Scripts</a>
<ul>
<li><a href="#Detailed-ed">2.5.1.1 Detailed Description of <samp><span class="command">ed</span></samp> Format</a>
<li><a href="#Example-ed">2.5.1.2 Example <samp><span class="command">ed</span></samp> Script</a>
</li></ul>
<li><a href="#Forward-ed">2.5.2 Forward <samp><span class="command">ed</span></samp> Scripts</a>
<li><a href="#RCS">2.5.3 <span class="sc">rcs</span> Scripts</a>
</li></ul>
<li><a href="#If_002dthen_002delse">2.6 Merging Files with If-then-else</a>
<ul>
<li><a href="#Line-Group-Formats">2.6.1 Line Group Formats</a>
<li><a href="#Line-Formats">2.6.2 Line Formats</a>
<li><a href="#Detailed-If_002dthen_002delse">2.6.3 Detailed Description of If-then-else Format</a>
<li><a href="#Example-If_002dthen_002delse">2.6.4 An Example of If-then-else Format</a>
</li></ul>
</li></ul>
<li><a name="toc_Incomplete-Lines" href="#Incomplete-Lines">3 Incomplete Lines</a>
<li><a name="toc_Comparing-Directories" href="#Comparing-Directories">4 Comparing Directories</a>
<li><a name="toc_Adjusting-Output" href="#Adjusting-Output">5 Making <samp><span class="command">diff</span></samp> Output Prettier</a>
<ul>
<li><a href="#Tabs">5.1 Preserving Tab Stop Alignment</a>
<li><a href="#Pagination">5.2 Paginating <samp><span class="command">diff</span></samp> Output</a>
</li></ul>
<li><a name="toc_diff-Performance" href="#diff-Performance">6 <samp><span class="command">diff</span></samp> Performance Tradeoffs</a>
<li><a name="toc_Comparing-Three-Files" href="#Comparing-Three-Files">7 Comparing Three Files</a>
<ul>
<li><a href="#Sample-diff3-Input">7.1 A Third Sample Input File</a>
<li><a href="#Detailed-diff3-Normal">7.2 Detailed Description of <samp><span class="command">diff3</span></samp> Normal Format</a>
<li><a href="#diff3-Hunks">7.3 <samp><span class="command">diff3</span></samp> Hunks</a>
<li><a href="#Example-diff3-Normal">7.4 An Example of <samp><span class="command">diff3</span></samp> Normal Format</a>
</li></ul>
<li><a name="toc_diff3-Merging" href="#diff3-Merging">8 Merging From a Common Ancestor</a>
<ul>
<li><a href="#Which-Changes">8.1 Selecting Which Changes to Incorporate</a>
<li><a href="#Marking-Conflicts">8.2 Marking Conflicts</a>
<li><a href="#Bypassing-ed">8.3 Generating the Merged Output Directly</a>
<li><a href="#Merging-Incomplete-Lines">8.4 How <samp><span class="command">diff3</span></samp> Merges Incomplete Lines</a>
<li><a href="#Saving-the-Changed-File">8.5 Saving the Changed File</a>
</li></ul>
<li><a name="toc_Interactive-Merging" href="#Interactive-Merging">9 Interactive Merging with <samp><span class="command">sdiff</span></samp></a>
<ul>
<li><a href="#sdiff-Option-Summary">9.1 Specifying <samp><span class="command">diff</span></samp> Options to <samp><span class="command">sdiff</span></samp></a>
<li><a href="#Merge-Commands">9.2 Merge Commands</a>
</li></ul>
<li><a name="toc_Merging-with-patch" href="#Merging-with-patch">10 Merging with <samp><span class="command">patch</span></samp></a>
<ul>
<li><a href="#patch-Input">10.1 Selecting the <samp><span class="command">patch</span></samp> Input Format</a>
<li><a href="#Revision-Control">10.2 Revision Control</a>
<li><a href="#Imperfect">10.3 Applying Imperfect Patches</a>
<ul>
<li><a href="#Changed-White-Space">10.3.1 Applying Patches with Changed White Space</a>
<li><a href="#Reversed-Patches">10.3.2 Applying Reversed Patches</a>
<li><a href="#Inexact">10.3.3 Helping <samp><span class="command">patch</span></samp> Find Inexact Matches</a>
<li><a href="#Dry-Runs">10.3.4 Predicting what <samp><span class="command">patch</span></samp> will do</a>
</li></ul>
<li><a href="#Creating-and-Removing">10.4 Creating and Removing Files</a>
<li><a href="#Patching-Time-Stamps">10.5 Updating Time Stamps on Patched Files</a>
<li><a href="#Multiple-Patches">10.6 Multiple Patches in a File</a>
<li><a href="#patch-Directories">10.7 Applying Patches in Other Directories</a>
<li><a href="#Backups">10.8 Backup Files</a>
<li><a href="#Backup-Names">10.9 Backup File Names</a>
<li><a href="#Reject-Names">10.10 Reject File Names</a>
<li><a href="#patch-Messages">10.11 Messages and Questions from <samp><span class="command">patch</span></samp></a>
<ul>
<li><a href="#More-or-Fewer-Messages">10.11.1 Controlling the Verbosity of <samp><span class="command">patch</span></samp></a>
<li><a href="#patch-and-Keyboard-Input">10.11.2 Inhibiting Keyboard Input</a>
<li><a href="#patch-Quoting-Style">10.11.3 <samp><span class="command">patch</span></samp> Quoting Style</a>
</li></ul>
<li><a href="#patch-and-POSIX">10.12 <samp><span class="command">patch</span></samp> and the <span class="sc">posix</span> Standard</a>
<li><a href="#patch-and-Tradition">10.13 <span class="sc">gnu</span> <samp><span class="command">patch</span></samp> and Traditional <samp><span class="command">patch</span></samp></a>
</li></ul>
<li><a name="toc_Making-Patches" href="#Making-Patches">11 Tips for Making and Using Patches</a>
<ul>
<li><a href="#Tips-for-Patch-Producers">11.1 Tips for Patch Producers</a>
<li><a href="#Tips-for-Patch-Consumers">11.2 Tips for Patch Consumers</a>
<li><a href="#Avoiding-Common-Mistakes">11.3 Avoiding Common Mistakes</a>
<li><a href="#Generating-Smaller-Patches">11.4 Generating Smaller Patches</a>
</li></ul>
<li><a name="toc_Invoking-cmp" href="#Invoking-cmp">12 Invoking <samp><span class="command">cmp</span></samp></a>
<ul>
<li><a href="#cmp-Options">12.1 Options to <samp><span class="command">cmp</span></samp></a>
</li></ul>
<li><a name="toc_Invoking-diff" href="#Invoking-diff">13 Invoking <samp><span class="command">diff</span></samp></a>
<ul>
<li><a href="#diff-Options">13.1 Options to <samp><span class="command">diff</span></samp></a>
</li></ul>
<li><a name="toc_Invoking-diff3" href="#Invoking-diff3">14 Invoking <samp><span class="command">diff3</span></samp></a>
<ul>
<li><a href="#diff3-Options">14.1 Options to <samp><span class="command">diff3</span></samp></a>
</li></ul>
<li><a name="toc_Invoking-patch" href="#Invoking-patch">15 Invoking <samp><span class="command">patch</span></samp></a>
<ul>
<li><a href="#patch-Options">15.1 Options to <samp><span class="command">patch</span></samp></a>
</li></ul>
<li><a name="toc_Invoking-sdiff" href="#Invoking-sdiff">16 Invoking <samp><span class="command">sdiff</span></samp></a>
<ul>
<li><a href="#sdiff-Options">16.1 Options to <samp><span class="command">sdiff</span></samp></a>
</li></ul>
<li><a name="toc_Standards-conformance" href="#Standards-conformance">17 Standards conformance</a>
<li><a name="toc_Projects" href="#Projects">18 Future Projects</a>
<ul>
<li><a href="#Shortcomings">18.1 Suggested Projects for Improving <span class="sc">gnu</span> <samp><span class="command">diff</span></samp> and <samp><span class="command">patch</span></samp></a>
<ul>
<li><a href="#Internationalization">18.1.1 Handling Multibyte and Varying-Width Characters</a>
<li><a href="#Changing-Structure">18.1.2 Handling Changes to the Directory Structure</a>
<li><a href="#Special-Files">18.1.3 Files that are Neither Directories Nor Regular Files</a>
<li><a href="#Unusual-File-Names">18.1.4 File Names that Contain Unusual Characters</a>
<li><a href="#Time-Stamp-Order">18.1.5 Outputting Diffs in Time Stamp Order</a>
<li><a href="#Ignoring-Changes">18.1.6 Ignoring Certain Changes</a>
<li><a href="#Speedups">18.1.7 Improving Performance</a>
</li></ul>
<li><a href="#Bugs">18.2 Reporting Bugs</a>
</li></ul>
<li><a name="toc_Copying-This-Manual" href="#Copying-This-Manual">Appendix A Copying This Manual</a>
<ul>
<li><a href="#GNU-Free-Documentation-License">A.1 GNU Free Documentation License</a>
<ul>
<li><a href="#GNU-Free-Documentation-License">A.1.1 ADDENDUM: How to use this License for your documents</a>
</li></ul>
</li></ul>
<li><a name="toc_Index" href="#Index">Appendix B Index</a>
</li></ul>
</div>

<div class="node">
<p><hr>
<a name="Top"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Overview">Overview</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#dir">(dir)</a>

</div>

<h2 class="unnumbered">Comparing and Merging Files</h2>

<p>This manual is for GNU Diffutils
(version 2.8.1, 5 April 2002),
and documents the <span class="sc">gnu</span> <samp><span class="command">diff</span></samp>, <samp><span class="command">diff3</span></samp>,
<samp><span class="command">sdiff</span></samp>, and <samp><span class="command">cmp</span></samp> commands for showing the
differences between files and the <span class="sc">gnu</span> <samp><span class="command">patch</span></samp> command for
using their output to update files.

   <p>Copyright &copy; 1992, 1993, 1994, 1998, 2001, 2002 Free
Software Foundation, Inc.

   <blockquote>
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.1 or
any later version published by the Free Software Foundation; with no
Invariant Sections, with the Front-Cover texts being &ldquo;A GNU Manual,&rdquo;
and with the Back-Cover Texts as in (a) below.  A copy of the
license is included in the section entitled &ldquo;GNU Free Documentation
License.&rdquo;

        <p>(a) The FSF's Back-Cover Text is: &ldquo;You have freedom to copy and modify
this GNU Manual, like GNU software.  Copies published by the Free
Software Foundation raise funds for GNU development.&rdquo;
</blockquote>

<ul class="menu">
<li><a accesskey="1" href="#Overview">Overview</a>:               Preliminary information. 
<li><a accesskey="2" href="#Comparison">Comparison</a>:             What file comparison means.

<li><a accesskey="3" href="#Output-Formats">Output Formats</a>:         Formats for two-way difference reports. 
<li><a accesskey="4" href="#Incomplete-Lines">Incomplete Lines</a>:       Lines that lack trailing newlines. 
<li><a accesskey="5" href="#Comparing-Directories">Comparing Directories</a>:  Comparing files and directories. 
<li><a accesskey="6" href="#Adjusting-Output">Adjusting Output</a>:       Making <samp><span class="command">diff</span></samp> output prettier. 
<li><a accesskey="7" href="#diff-Performance">diff Performance</a>:       Making <samp><span class="command">diff</span></samp> smarter or faster.

<li><a accesskey="8" href="#Comparing-Three-Files">Comparing Three Files</a>:  Formats for three-way difference reports. 
<li><a accesskey="9" href="#diff3-Merging">diff3 Merging</a>:          Merging from a common ancestor.

<li><a href="#Interactive-Merging">Interactive Merging</a>:    Interactive merging with <samp><span class="command">sdiff</span></samp>.

<li><a href="#Merging-with-patch">Merging with patch</a>:     Using <samp><span class="command">patch</span></samp> to change old files into new ones. 
<li><a href="#Making-Patches">Making Patches</a>:         Tips for making and using patch distributions.

<li><a href="#Invoking-cmp">Invoking cmp</a>:           Compare two files byte by byte. 
<li><a href="#Invoking-diff">Invoking diff</a>:          Compare two files line by line. 
<li><a href="#Invoking-diff3">Invoking diff3</a>:         Compare three files line by line. 
<li><a href="#Invoking-patch">Invoking patch</a>:         Apply a diff file to an original. 
<li><a href="#Invoking-sdiff">Invoking sdiff</a>:         Side-by-side merge of file differences.

<li><a href="#Standards-conformance">Standards conformance</a>:  Conformance to the <span class="sc">posix</span> standard. 
<li><a href="#Projects">Projects</a>:               If you've found a bug or other shortcoming.

<li><a href="#Copying-This-Manual">Copying This Manual</a>:    How to make copies of this manual. 
<li><a href="#Index">Index</a>:                  Index. 
</ul>

<div class="node">
<p><hr>
<a name="Overview"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Comparison">Comparison</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Top">Top</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Top">Top</a>

</div>

<h2 class="unnumbered">Overview</h2>

<p><a name="index-overview-of-_0040command_007bdiff_007d-and-_0040command_007bpatch_007d-1"></a>
Computer users often find occasion to ask how two files differ.  Perhaps
one file is a newer version of the other file.  Or maybe the two files
started out as identical copies but were changed by different people.

   <p>You can use the <samp><span class="command">diff</span></samp> command to show differences between two
files, or each corresponding file in two directories.  <samp><span class="command">diff</span></samp>
outputs differences between files line by line in any of several
formats, selectable by command line options.  This set of differences is
often called a <dfn>diff</dfn> or <dfn>patch</dfn>.  For files that are identical,
<samp><span class="command">diff</span></samp> normally produces no output; for binary (non-text) files,
<samp><span class="command">diff</span></samp> normally reports only that they are different.

   <p>You can use the <samp><span class="command">cmp</span></samp> command to show the byte and line numbers
where two files differ.  <samp><span class="command">cmp</span></samp> can also show all the bytes
that differ between the two files, side by side.  A way to compare
two files character by character is the Emacs command <kbd>M-x
compare-windows</kbd>.  See <a href="emacs.html#Other-Window">Other Window</a>, for more information on that command.

   <p>You can use the <samp><span class="command">diff3</span></samp> command to show differences among three
files.  When two people have made independent changes to a common
original, <samp><span class="command">diff3</span></samp> can report the differences between the original
and the two changed versions, and can produce a merged file that
contains both persons' changes together with warnings about conflicts.

   <p>You can use the <samp><span class="command">sdiff</span></samp> command to merge two files interactively.

   <p>You can use the set of differences produced by <samp><span class="command">diff</span></samp> to distribute
updates to text files (such as program source code) to other people. 
This method is especially useful when the differences are small compared
to the complete files.  Given <samp><span class="command">diff</span></samp> output, you can use the
<samp><span class="command">patch</span></samp> program to update, or <dfn>patch</dfn>, a copy of the file.  If you
think of <samp><span class="command">diff</span></samp> as subtracting one file from another to produce
their difference, you can think of <samp><span class="command">patch</span></samp> as adding the difference
to one file to reproduce the other.

   <p>This manual first concentrates on making diffs, and later shows how to
use diffs to update files.

   <p><span class="sc">gnu</span> <samp><span class="command">diff</span></samp> was written by Paul Eggert, Mike Haertel,
David Hayes, Richard Stallman, and Len Tower.  Wayne Davison designed and
implemented the unified output format.  The basic algorithm is described
in &ldquo;An O(ND) Difference Algorithm and its Variations&rdquo;, Eugene W. Myers,
<cite>Algorithmica</cite> Vol. 1 No. 2, 1986, pp. 251&ndash;266; and in &ldquo;A File
Comparison Program&rdquo;, Webb Miller and Eugene W. Myers,
<cite>Software&mdash;Practice and Experience</cite> Vol. 15 No. 11, 1985,
pp. 1025&ndash;1040. 
<!-- From: "Gene Myers" <gene@cs.arizona.edu> -->
<!-- They are about the same basic algorithm; the Algorithmica -->
<!-- paper gives a rigorous treatment and the sub-algorithm for -->
<!-- delivering scripts and should be the primary reference, but -->
<!-- both should be mentioned. -->
The algorithm was independently discovered as described in
&ldquo;Algorithms for Approximate String Matching&rdquo;,
E. Ukkonen, <cite>Information and Control</cite> Vol. 64, 1985, pp. 100&ndash;118. 
<!-- From: "Gene Myers" <gene@cs.arizona.edu> -->
<!-- Date: Wed, 29 Sep 1993 08:27:55 MST -->
<!-- Ukkonen should be given credit for also discovering the algorithm used -->
<!-- in GNU diff. -->

   <p><span class="sc">gnu</span> <samp><span class="command">diff3</span></samp> was written by Randy Smith.  <span class="sc">gnu</span>
<samp><span class="command">sdiff</span></samp> was written by Thomas Lord.  <span class="sc">gnu</span> <samp><span class="command">cmp</span></samp>
was written by Torbjorn Granlund and David MacKenzie.

   <p><samp><span class="command">patch</span></samp> was written mainly by Larry Wall and Paul Eggert;
several <span class="sc">gnu</span> enhancements were contributed by Wayne Davison and
David MacKenzie.  Parts of this manual are adapted from a manual page
written by Larry Wall, with his permission.

<div class="node">
<p><hr>
<a name="Comparison"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Output-Formats">Output Formats</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Overview">Overview</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Top">Top</a>

</div>

<h2 class="chapter">1 What Comparison Means</h2>

<p><a name="index-introduction-2"></a>
There are several ways to think about the differences between two files. 
One way to think of the differences is as a series of lines that were
deleted from, inserted in, or changed in one file to produce the other
file.  <samp><span class="command">diff</span></samp> compares two files line by line, finds groups of
lines that differ, and reports each group of differing lines.  It can
report the differing lines in several formats, which have different
purposes.

   <p><span class="sc">gnu</span> <samp><span class="command">diff</span></samp> can show whether files are different without detailing
the differences.  It also provides ways to suppress certain kinds of
differences that are not important to you.  Most commonly, such
differences are changes in the amount of white space between words or
lines.  <samp><span class="command">diff</span></samp> also provides ways to suppress differences in
alphabetic case or in lines that match a regular expression that you
provide.  These options can accumulate; for example, you can ignore
changes in both white space and alphabetic case.

   <p>Another way to think of the differences between two files is as a
sequence of pairs of bytes that can be either identical or
different.  <samp><span class="command">cmp</span></samp> reports the differences between two files
byte by byte, instead of line by line.  As a result, it is often
more useful than <samp><span class="command">diff</span></samp> for comparing binary files.  For text
files, <samp><span class="command">cmp</span></samp> is useful mainly when you want to know only whether
two files are identical, or whether one file is a prefix of the other.

   <p>To illustrate the effect that considering changes byte by byte
can have compared with considering them line by line, think of what
happens if a single newline character is added to the beginning of a
file.  If that file is then compared with an otherwise identical file
that lacks the newline at the beginning, <samp><span class="command">diff</span></samp> will report that a
blank line has been added to the file, while <samp><span class="command">cmp</span></samp> will report that
almost every byte of the two files differs.

   <p><samp><span class="command">diff3</span></samp> normally compares three input files line by line, finds
groups of lines that differ, and reports each group of differing lines. 
Its output is designed to make it easy to inspect two different sets of
changes to the same file.

<ul class="menu">
<li><a accesskey="1" href="#Hunks">Hunks</a>:              Groups of differing lines. 
<li><a accesskey="2" href="#White-Space">White Space</a>:        Suppressing differences in white space. 
<li><a accesskey="3" href="#Blank-Lines">Blank Lines</a>:        Suppressing differences in blank lines. 
<li><a accesskey="4" href="#Case-Folding">Case Folding</a>:       Suppressing differences in alphabetic case. 
<li><a accesskey="5" href="#Specified-Folding">Specified Folding</a>:  Suppressing differences that match regular expressions. 
<li><a accesskey="6" href="#Brief">Brief</a>:              Summarizing which files are different. 
<li><a accesskey="7" href="#Binary">Binary</a>:             Comparing binary files or forcing text comparisons. 
</ul>

<div class="node">
<p><hr>
<a name="Hunks"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#White-Space">White Space</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Comparison">Comparison</a>

</div>

<h3 class="section">1.1 Hunks</h3>

<p><a name="index-hunks-3"></a>
When comparing two files, <samp><span class="command">diff</span></samp> finds sequences of lines common to
both files, interspersed with groups of differing lines called
<dfn>hunks</dfn>.  Comparing two identical files yields one sequence of
common lines and no hunks, because no lines differ.  Comparing two
entirely different files yields no common lines and one large hunk that
contains all lines of both files.  In general, there are many ways to
match up lines between two given files.  <samp><span class="command">diff</span></samp> tries to minimize
the total hunk size by finding large sequences of common lines
interspersed with small hunks of differing lines.

   <p>For example, suppose the file <samp><span class="file">F</span></samp> contains the three lines
`<samp><span class="samp">a</span></samp>', `<samp><span class="samp">b</span></samp>', `<samp><span class="samp">c</span></samp>', and the file <samp><span class="file">G</span></samp> contains the same
three lines in reverse order `<samp><span class="samp">c</span></samp>', `<samp><span class="samp">b</span></samp>', `<samp><span class="samp">a</span></samp>'.  If
<samp><span class="command">diff</span></samp> finds the line `<samp><span class="samp">c</span></samp>' as common, then the command
`<samp><span class="samp">diff F G</span></samp>' produces this output:

<pre class="example">     1,2d0
     &lt; a
     &lt; b
     3a2,3
     &gt; b
     &gt; a
</pre>
   <p class="noindent">But if <samp><span class="command">diff</span></samp> notices the common line `<samp><span class="samp">b</span></samp>' instead, it produces
this output:

<pre class="example">     1c1
     &lt; a
     ---
     &gt; c
     3c3
     &lt; c
     ---
     &gt; a
</pre>
   <p class="noindent">It is also possible to find `<samp><span class="samp">a</span></samp>' as the common line.  <samp><span class="command">diff</span></samp>
does not always find an optimal matching between the files; it takes
shortcuts to run faster.  But its output is usually close to the
shortest possible.  You can adjust this tradeoff with the
<samp><span class="option">--minimal</span></samp> option (see <a href="#diff-Performance">diff Performance</a>).

<div class="node">
<p><hr>
<a name="White-Space"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Blank-Lines">Blank Lines</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Hunks">Hunks</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Comparison">Comparison</a>

</div>

<h3 class="section">1.2 Suppressing Differences in Blank and Tab Spacing</h3>

<p><a name="index-blank-and-tab-difference-suppression-4"></a><a name="index-tab-and-blank-difference-suppression-5"></a>
The <samp><span class="option">-E</span></samp> and <samp><span class="option">--ignore-tab-expansion</span></samp> options ignore the
distinction between tabs and spaces on input.  A tab is considered to be
equivalent to the number of spaces to the next tab stop.  <samp><span class="command">diff</span></samp>
assumes that tab stops are set every 8 print columns.

   <p>The <samp><span class="option">-b</span></samp> and <samp><span class="option">--ignore-space-change</span></samp> options are stronger. 
They ignore white space at line end, and consider all other sequences of
one or more white space characters to be equivalent.  With these
options, <samp><span class="command">diff</span></samp> considers the following two lines to be equivalent,
where `<samp><span class="samp">$</span></samp>' denotes the line end:

<pre class="example">     Here lyeth  muche rychnesse  in lytell space.   -- John Heywood$
     Here lyeth muche rychnesse in lytell space. -- John Heywood   $
</pre>
   <p>The <samp><span class="option">-w</span></samp> and <samp><span class="option">--ignore-all-space</span></samp> options are stronger still. 
They ignore difference even if one line has white space where
the other line has none.  <dfn>White space</dfn> characters include
tab, newline, vertical tab, form feed, carriage return, and space;
some locales may define additional characters to be white space. 
With these options, <samp><span class="command">diff</span></samp> considers the
following two lines to be equivalent, where `<samp><span class="samp">$</span></samp>' denotes the line
end and `<samp><span class="samp">^M</span></samp>' denotes a carriage return:

<pre class="example">     Here lyeth  muche  rychnesse in lytell space.--  John Heywood$
       He relyeth much erychnes  seinly tells pace.  --John Heywood   ^M$
</pre>
   <div class="node">
<p><hr>
<a name="Blank-Lines"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Case-Folding">Case Folding</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#White-Space">White Space</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Comparison">Comparison</a>

</div>

<h3 class="section">1.3 Suppressing Differences in Blank Lines</h3>

<p><a name="index-blank-line-difference-suppression-6"></a>
The <samp><span class="option">-B</span></samp> and <samp><span class="option">--ignore-blank-lines</span></samp> options ignore insertions
or deletions of blank lines.  These options affect only lines
that are completely empty; they do not affect lines that look empty but
contain space or tab characters.  With these options, for example, a
file containing
<pre class="example">     1.  A point is that which has no part.
     
     2.  A line is breadthless length.
     -- Euclid, The Elements, I
</pre>
   <p class="noindent">is considered identical to a file containing
<pre class="example">     1.  A point is that which has no part.
     2.  A line is breadthless length.
     
     
     -- Euclid, The Elements, I
</pre>
   <div class="node">
<p><hr>
<a name="Case-Folding"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Specified-Folding">Specified Folding</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Blank-Lines">Blank Lines</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Comparison">Comparison</a>

</div>

<h3 class="section">1.4 Suppressing Case Differences</h3>

<p><a name="index-case-difference-suppression-7"></a>
<span class="sc">gnu</span> <samp><span class="command">diff</span></samp> can treat lower case letters as equivalent to their
upper case counterparts, so that, for example, it considers `<samp><span class="samp">Funky
Stuff</span></samp>', `<samp><span class="samp">funky STUFF</span></samp>', and `<samp><span class="samp">fUNKy stuFf</span></samp>' to all be the same. 
To request this, use the <samp><span class="option">-i</span></samp> or <samp><span class="option">--ignore-case</span></samp> option.

<div class="node">
<p><hr>
<a name="Specified-Folding"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Brief">Brief</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Case-Folding">Case Folding</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Comparison">Comparison</a>

</div>

<h3 class="section">1.5 Suppressing Lines Matching a Regular Expression</h3>

<p><a name="index-regular-expression-suppression-8"></a>
To ignore insertions and deletions of lines that match a
<samp><span class="command">grep</span></samp>-style regular expression, use the <samp><span class="option">-I
</span><var>regexp</var></samp> or <samp><span class="option">--ignore-matching-lines=</span><var>regexp</var></samp> option. 
You should escape
regular expressions that contain shell metacharacters to prevent the
shell from expanding them.  For example, `<samp><span class="samp">diff -I '^[[:digit:]]'</span></samp>' ignores
all changes to lines beginning with a digit.

   <p>However, <samp><span class="option">-I</span></samp> only ignores the insertion or deletion of lines that
contain the regular expression if every changed line in the hunk&mdash;every
insertion and every deletion&mdash;matches the regular expression.  In other
words, for each nonignorable change, <samp><span class="command">diff</span></samp> prints the complete set
of changes in its vicinity, including the ignorable ones.

   <p>You can specify more than one regular expression for lines to ignore by
using more than one <samp><span class="option">-I</span></samp> option.  <samp><span class="command">diff</span></samp> tries to match each
line against each regular expression.

<div class="node">
<p><hr>
<a name="Brief"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Binary">Binary</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Specified-Folding">Specified Folding</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Comparison">Comparison</a>

</div>

<h3 class="section">1.6 Summarizing Which Files Differ</h3>

<p><a name="index-summarizing-which-files-differ-9"></a><a name="index-brief-difference-reports-10"></a>
When you only want to find out whether files are different, and you
don't care what the differences are, you can use the summary output
format.  In this format, instead of showing the differences between the
files, <samp><span class="command">diff</span></samp> simply reports whether files differ.  The <samp><span class="option">-q</span></samp>
and <samp><span class="option">--brief</span></samp> options select this output format.

   <p>This format is especially useful when comparing the contents of two
directories.  It is also much faster than doing the normal line by line
comparisons, because <samp><span class="command">diff</span></samp> can stop analyzing the files as soon as
it knows that there are any differences.

   <p>You can also get a brief indication of whether two files differ by using
<samp><span class="command">cmp</span></samp>.  For files that are identical, <samp><span class="command">cmp</span></samp> produces no
output.  When the files differ, by default, <samp><span class="command">cmp</span></samp> outputs the byte
and line number where the first difference occurs.  You can use
the <samp><span class="option">-s</span></samp> option to suppress that information, so that <samp><span class="command">cmp</span></samp>
produces no output and reports whether the files differ using only its
exit status (see <a href="#Invoking-cmp">Invoking cmp</a>).

<!-- Fix this. -->
<p>Unlike <samp><span class="command">diff</span></samp>, <samp><span class="command">cmp</span></samp> cannot compare directories; it can only
compare two files.

<div class="node">
<p><hr>
<a name="Binary"></a>
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Brief">Brief</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Comparison">Comparison</a>

</div>

<h3 class="section">1.7 Binary Files and Forcing Text Comparisons</h3>

<p><a name="index-binary-file-diff-11"></a><a name="index-text-versus-binary-diff-12"></a>
If <samp><span class="command">diff</span></samp> thinks that either of the two files it is comparing is
binary (a non-text file), it normally treats that pair of files much as
if the summary output format had been selected (see <a href="#Brief">Brief</a>), and
reports only that the binary files are different.  This is because line
by line comparisons are usually not meaningful for binary files.

   <p><samp><span class="command">diff</span></samp> determines whether a file is text or binary by checking the
first few bytes in the file; the exact number of bytes is system
dependent, but it is typically several thousand.  If every byte in
that part of the file is non-null, <samp><span class="command">diff</span></samp> considers the file to be
text; otherwise it considers the file to be binary.

   <p>Sometimes you might want to force <samp><span class="command">diff</span></samp> to consider files to be
text.  For example, you might be comparing text files that contain
null characters; <samp><span class="command">diff</span></samp> would erroneously decide that those are
non-text files.  Or you might be comparing documents that are in a
format used by a word processing system that uses null characters to
indicate special formatting.  You can force <samp><span class="command">diff</span></samp> to consider all
files to be text files, and compare them line by line, by using the
<samp><span class="option">-a</span></samp> or <samp><span class="option">--text</span></samp> option.  If the files you compare using this
option do not in fact contain text, they will probably contain few
newline characters, and the <samp><span class="command">diff</span></samp> output will consist of hunks
showing differences between long lines of whatever characters the files
contain.

   <p>You can also force <samp><span class="command">diff</span></samp> to consider all files to be binary files,
and report only whether they differ (but not how).  Use the
<samp><span class="option">-q</span></samp> or <samp><span class="option">--brief</span></samp> option for this.

   <p>Differing binary files are considered to cause trouble because the
resulting <samp><span class="command">diff</span></samp> output does not capture all the differences. 
This trouble causes <samp><span class="command">diff</span></samp> to exit with status 2.  However,
this trouble cannot occur with the <samp><span class="option">--a</span></samp> or <samp><span class="option">--text</span></samp>
option, or with the <samp><span class="option">-q</span></samp> or <samp><span class="option">--brief</span></samp> option, as these
options both cause <samp><span class="command">diff</span></samp> to treat binary files like text
files.

   <p>In operating systems that distinguish between text and binary files,
<samp><span class="command">diff</span></samp> normally reads and writes all data as text.  Use the
<samp><span class="option">--binary</span></samp> option to force <samp><span class="command">diff</span></samp> to read and write binary
data instead.  This option has no effect on a <span class="sc">posix</span>-compliant system
like <span class="sc">gnu</span> or traditional Unix.  However, many personal computer
operating systems represent the end of a line with a carriage return
followed by a newline.  On such systems, <samp><span class="command">diff</span></samp> normally ignores
these carriage returns on input and generates them at the end of each
output line, but with the <samp><span class="option">--binary</span></samp> option <samp><span class="command">diff</span></samp> treats
each carriage return as just another input character, and does not
generate a carriage return at the end of each output line.  This can be
useful when dealing with non-text files that are meant to be
interchanged with <span class="sc">posix</span>-compliant systems.

   <p>The <samp><span class="option">--strip-trailing-cr</span></samp> causes <samp><span class="command">diff</span></samp> to treat input
lines that end in carriage return followed by newline as if they end
in plain newline.  This can be useful when comparing text that is
imperfectly imported from many personal computer operating systems. 
This option affects how lines are read, which in turn affects how they
are compared and output.

   <p>If you want to compare two files byte by byte, you can use the
<samp><span class="command">cmp</span></samp> program with the <samp><span class="option">-l</span></samp> option to show the values
of each differing byte in the two files.  With <span class="sc">gnu</span> <samp><span class="command">cmp</span></samp>,
you can also use the <samp><span class="option">-b</span></samp> option to show the <span class="sc">ascii</span>
representation of those bytes.  See <a href="#Invoking-cmp">Invoking cmp</a>, for more
information.

   <p>If <samp><span class="command">diff3</span></samp> thinks that any of the files it is comparing is binary
(a non-text file), it normally reports an error, because such
comparisons are usually not useful.  <samp><span class="command">diff3</span></samp> uses the same test as
<samp><span class="command">diff</span></samp> to decide whether a file is binary.  As with <samp><span class="command">diff</span></samp>, if
the input files contain a few non-text bytes but otherwise are like
text files, you can force <samp><span class="command">diff3</span></samp> to consider all files to be text
files and compare them line by line by using the <samp><span class="option">-a</span></samp> or
<samp><span class="option">--text</span></samp> options.

<div class="node">
<p><hr>
<a name="Output-Formats"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Incomplete-Lines">Incomplete Lines</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Comparison">Comparison</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Top">Top</a>

</div>

<h2 class="chapter">2 <samp><span class="command">diff</span></samp> Output Formats</h2>

<p><a name="index-output-formats-13"></a><a name="index-format-of-_0040command_007bdiff_007d-output-14"></a>
<samp><span class="command">diff</span></samp> has several mutually exclusive options for output format. 
The following sections describe each format, illustrating how
<samp><span class="command">diff</span></samp> reports the differences between two sample input files.

<ul class="menu">
<li><a accesskey="1" href="#Sample-diff-Input">Sample diff Input</a>:  Sample <samp><span class="command">diff</span></samp> input files for examples. 
<li><a accesskey="2" href="#Normal">Normal</a>:             Showing differences without surrounding text. 
<li><a accesskey="3" href="#Context">Context</a>:            Showing differences with the surrounding text. 
<li><a accesskey="4" href="#Side-by-Side">Side by Side</a>:       Showing differences in two columns. 
<li><a accesskey="5" href="#Scripts">Scripts</a>:            Generating scripts for other programs. 
<li><a accesskey="6" href="#If_002dthen_002delse">If-then-else</a>:       Merging files with if-then-else. 
</ul>

<div class="node">
<p><hr>
<a name="Sample-diff-Input"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Normal">Normal</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Output-Formats">Output Formats</a>

</div>

<h3 class="section">2.1 Two Sample Input Files</h3>

<p><a name="index-g_t_0040command_007bdiff_007d-sample-input-15"></a><a name="index-sample-input-for-_0040command_007bdiff_007d-16"></a>
Here are two sample files that we will use in numerous examples to
illustrate the output of <samp><span class="command">diff</span></samp> and how various options can change
it.

   <p>This is the file <samp><span class="file">lao</span></samp>:

<pre class="example">     The Way that can be told of is not the eternal Way;
     The name that can be named is not the eternal name.
     The Nameless is the origin of Heaven and Earth;
     The Named is the mother of all things.
     Therefore let there always be non-being,
       so we may see their subtlety,
     And let there always be being,
       so we may see their outcome.
     The two are the same,
     But after they are produced,
       they have different names.
</pre>
   <p>This is the file <samp><span class="file">tzu</span></samp>:

<pre class="example">     The Nameless is the origin of Heaven and Earth;
     The named is the mother of all things.
     
     Therefore let there always be non-being,
       so we may see their subtlety,
     And let there always be being,
       so we may see their outcome.
     The two are the same,
     But after they are produced,
       they have different names.
     They both may be called deep and profound.
     Deeper and more profound,
     The door of all subtleties!
</pre>
   <p>In this example, the first hunk contains just the first two lines of
<samp><span class="file">lao</span></samp>, the second hunk contains the fourth line of <samp><span class="file">lao</span></samp>
opposing the second and third lines of <samp><span class="file">tzu</span></samp>, and the last hunk
contains just the last three lines of <samp><span class="file">tzu</span></samp>.

<div class="node">
<p><hr>
<a name="Normal"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Context">Context</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Sample-diff-Input">Sample diff Input</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Output-Formats">Output Formats</a>

</div>

<h3 class="section">2.2 Showing Differences Without Context</h3>

<p><a name="index-normal-output-format-17"></a><a name="index-g_t_0040samp_007b_003c_007d-output-format-18"></a>
The &ldquo;normal&rdquo; <samp><span class="command">diff</span></samp> output format shows each hunk of differences
without any surrounding context.  Sometimes such output is the clearest
way to see how lines have changed, without the clutter of nearby
unchanged lines (although you can get similar results with the context
or unified formats by using 0 lines of context).  However, this format
is no longer widely used for sending out patches; for that purpose, the
context format (see <a href="#Context-Format">Context Format</a>) and the unified format
(see <a href="#Unified-Format">Unified Format</a>) are superior.  Normal format is the default for
compatibility with older versions of <samp><span class="command">diff</span></samp> and the <span class="sc">posix</span>
standard.  Use the <samp><span class="option">--normal</span></samp> option to select this output
format explicitly.

<ul class="menu">
<li><a accesskey="1" href="#Detailed-Normal">Detailed Normal</a>:  A detailed description of normal output format. 
<li><a accesskey="2" href="#Example-Normal">Example Normal</a>:   Sample output in the normal format. 
</ul>

<div class="node">
<p><hr>
<a name="Detailed-Normal"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Example-Normal">Example Normal</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Normal">Normal</a>

</div>

<h4 class="subsection">2.2.1 Detailed Description of Normal Format</h4>

<p>The normal output format consists of one or more hunks of differences;
each hunk shows one area where the files differ.  Normal format hunks
look like this:

<pre class="example">     <var>change-command</var>
     &lt; <var>from-file-line</var>
     &lt; <var>from-file-line</var>...
     ---
     &gt; <var>to-file-line</var>
     &gt; <var>to-file-line</var>...
</pre>
   <p>There are three types of change commands.  Each consists of a line
number or comma-separated range of lines in the first file, a single
character indicating the kind of change to make, and a line number or
comma-separated range of lines in the second file.  All line numbers are
the original line numbers in each file.  The types of change commands
are:

     <dl>
<dt>`<samp><var>l</var><span class="samp">a</span><var>r</var></samp>'<dd>Add the lines in range <var>r</var> of the second file after line <var>l</var> of
the first file.  For example, `<samp><span class="samp">8a12,15</span></samp>' means append lines 12&ndash;15
of file 2 after line 8 of file 1; or, if changing file 2 into file 1,
delete lines 12&ndash;15 of file 2.

     <br><dt>`<samp><var>f</var><span class="samp">c</span><var>t</var></samp>'<dd>Replace the lines in range <var>f</var> of the first file with lines in range
<var>t</var> of the second file.  This is like a combined add and delete, but
more compact.  For example, `<samp><span class="samp">5,7c8,10</span></samp>' means change lines 5&ndash;7 of
file 1 to read as lines 8&ndash;10 of file 2; or, if changing file 2 into
file 1, change lines 8&ndash;10 of file 2 to read as lines 5&ndash;7 of file 1.

     <br><dt>`<samp><var>r</var><span class="samp">d</span><var>l</var></samp>'<dd>Delete the lines in range <var>r</var> from the first file; line <var>l</var> is where
they would have appeared in the second file had they not been deleted. 
For example, `<samp><span class="samp">5,7d3</span></samp>' means delete lines 5&ndash;7 of file 1; or, if
changing file 2 into file 1, append lines 5&ndash;7 of file 1 after line 3 of
file 2. 
</dl>

<div class="node">
<p><hr>
<a name="Example-Normal"></a>
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Detailed-Normal">Detailed Normal</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Normal">Normal</a>

</div>

<h4 class="subsection">2.2.2 An Example of Normal Format</h4>

<p>Here is the output of the command `<samp><span class="samp">diff lao tzu</span></samp>'
(see <a href="#Sample-diff-Input">Sample diff Input</a>, for the complete contents of the two files). 
Notice that it shows only the lines that are different between the two
files.

<pre class="example">     1,2d0
     &lt; The Way that can be told of is not the eternal Way;
     &lt; The name that can be named is not the eternal name.
     4c2,3
     &lt; The Named is the mother of all things.
     ---
     &gt; The named is the mother of all things.
     &gt;
     11a11,13
     &gt; They both may be called deep and profound.
     &gt; Deeper and more profound,
     &gt; The door of all subtleties!
</pre>
   <div class="node">
<p><hr>
<a name="Context"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Side-by-Side">Side by Side</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Normal">Normal</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Output-Formats">Output Formats</a>

</div>

<h3 class="section">2.3 Showing Differences in Their Context</h3>

<p><a name="index-context-output-format-19"></a><a name="index-g_t_0040samp_007b_0021_007d-output-format-20"></a>
Usually, when you are looking at the differences between files, you will
also want to see the parts of the files near the lines that differ, to
help you understand exactly what has changed.  These nearby parts of the
files are called the <dfn>context</dfn>.

   <p><span class="sc">gnu</span> <samp><span class="command">diff</span></samp> provides two output formats that show context
around the differing lines: <dfn>context format</dfn> and <dfn>unified
format</dfn>.  It can optionally show in which function or section of the
file the differing lines are found.

   <p>If you are distributing new versions of files to other people in the
form of <samp><span class="command">diff</span></samp> output, you should use one of the output formats
that show context so that they can apply the diffs even if they have
made small changes of their own to the files.  <samp><span class="command">patch</span></samp> can apply
the diffs in this case by searching in the files for the lines of
context around the differing lines; if those lines are actually a few
lines away from where the diff says they are, <samp><span class="command">patch</span></samp> can adjust
the line numbers accordingly and still apply the diff correctly. 
See <a href="#Imperfect">Imperfect</a>, for more information on using <samp><span class="command">patch</span></samp> to apply
imperfect diffs.

<ul class="menu">
<li><a accesskey="1" href="#Context-Format">Context Format</a>:   An output format that shows surrounding lines. 
<li><a accesskey="2" href="#Unified-Format">Unified Format</a>:   A more compact output format that shows context. 
<li><a accesskey="3" href="#Sections">Sections</a>:         Showing which sections of the files differences are in. 
<li><a accesskey="4" href="#Alternate-Names">Alternate Names</a>:  Showing alternate file names in context headers. 
</ul>

<div class="node">
<p><hr>
<a name="Context-Format"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Unified-Format">Unified Format</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Context">Context</a>

</div>

<h4 class="subsection">2.3.1 Context Format</h4>

<p>The context output format shows several lines of context around the
lines that differ.  It is the standard format for distributing updates
to source code.

   <p>To select this output format, use the <samp><span class="option">-C </span><var>lines</var></samp>,
<samp><span class="option">--context[=</span><var>lines</var><span class="option">]</span></samp>, or <samp><span class="option">-c</span></samp> option.  The
argument <var>lines</var> that some of these options take is the number of
lines of context to show.  If you do not specify <var>lines</var>, it
defaults to three.  For proper operation, <samp><span class="command">patch</span></samp> typically needs
at least two lines of context.

<ul class="menu">
<li><a accesskey="1" href="#Detailed-Context">Detailed Context</a>:  A detailed description of the context output format. 
<li><a accesskey="2" href="#Example-Context">Example Context</a>:   Sample output in context format. 
<li><a accesskey="3" href="#Less-Context">Less Context</a>:      Another sample with less context. 
</ul>

<div class="node">
<p><hr>
<a name="Detailed-Context"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Example-Context">Example Context</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Context-Format">Context Format</a>

</div>

<h5 class="subsubsection">2.3.1.1 Detailed Description of Context Format</h5>

<p>The context output format starts with a two-line header, which looks
like this:

<pre class="example">     *** <var>from-file</var> <var>from-file-modification-time</var>
     --- <var>to-file</var> <var>to-file-modification time</var>
</pre>
   <p class="noindent"><a name="index-LC_005fTIME-21"></a><a name="index-time-stamp-format_002c-context-diffs-22"></a>The time stamp normally looks like `<samp><span class="samp">2002-02-21 23:30:39.942229878
-0800</span></samp>' to indicate the date, time with fractional seconds, and time
zone in <a href="ftp://ftp.isi.edu/in-notes/rfc2822.txt">Internet RFC 2822 format</a>.  However, a traditional time stamp like `<samp><span class="samp">Thu Feb 21
23:30:39 2002</span></samp>' is used if the <samp><span class="env">LC_TIME</span></samp> locale category is either
`<samp><span class="samp">C</span></samp>' or `<samp><span class="samp">POSIX</span></samp>'.

   <p>You can change the header's content with the
<samp><span class="option">--label=</span><var>label</var></samp> option; see <a href="#Alternate-Names">Alternate Names</a>.

   <p>Next come one or more hunks of differences; each hunk shows one area
where the files differ.  Context format hunks look like this:

<pre class="example">     ***************
     *** <var>from-file-line-range</var> ****
       <var>from-file-line</var>
       <var>from-file-line</var>...
     --- <var>to-file-line-range</var> ----
       <var>to-file-line</var>
       <var>to-file-line</var>...
</pre>
   <p>The lines of context around the lines that differ start with two space
characters.  The lines that differ between the two files start with one
of the following indicator characters, followed by a space character:

     <dl>
<dt>`<samp><span class="samp">!</span></samp>'<dd>A line that is part of a group of one or more lines that changed between
the two files.  There is a corresponding group of lines marked with
`<samp><span class="samp">!</span></samp>' in the part of this hunk for the other file.

     <br><dt>`<samp><span class="samp">+</span></samp>'<dd>An &ldquo;inserted&rdquo; line in the second file that corresponds to nothing in
the first file.

     <br><dt>`<samp><span class="samp">-</span></samp>'<dd>A &ldquo;deleted&rdquo; line in the first file that corresponds to nothing in the
second file. 
</dl>

   <p>If all of the changes in a hunk are insertions, the lines of
<var>from-file</var> are omitted.  If all of the changes are deletions, the
lines of <var>to-file</var> are omitted.

<div class="node">
<p><hr>
<a name="Example-Context"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Less-Context">Less Context</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Detailed-Context">Detailed Context</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Context-Format">Context Format</a>

</div>

<h5 class="subsubsection">2.3.1.2 An Example of Context Format</h5>

<p>Here is the output of `<samp><span class="samp">diff -c lao tzu</span></samp>' (see <a href="#Sample-diff-Input">Sample diff Input</a>,
for the complete contents of the two files).  Notice that up to three
lines that are not different are shown around each line that is
different; they are the context lines.  Also notice that the first two
hunks have run together, because their contents overlap.

<pre class="example">     *** lao	2002-02-21 23:30:39.942229878 -0800
     --- tzu	2002-02-21 23:30:50.442260588 -0800
     ***************
     *** 1,7 ****
     - The Way that can be told of is not the eternal Way;
     - The name that can be named is not the eternal name.
       The Nameless is the origin of Heaven and Earth;
     ! The Named is the mother of all things.
       Therefore let there always be non-being,
         so we may see their subtlety,
       And let there always be being,
     --- 1,6 ----
       The Nameless is the origin of Heaven and Earth;
     ! The named is the mother of all things.
     !
       Therefore let there always be non-being,
         so we may see their subtlety,
       And let there always be being,
     ***************
     *** 9,11 ****
     --- 8,13 ----
       The two are the same,
       But after they are produced,
         they have different names.
     + They both may be called deep and profound.
     + Deeper and more profound,
     + The door of all subtleties!
</pre>
   <div class="node">
<p><hr>
<a name="Less-Context"></a>
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Example-Context">Example Context</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Context-Format">Context Format</a>

</div>

<h5 class="subsubsection">2.3.1.3 An Example of Context Format with Less Context</h5>

<p>Here is the output of `<samp><span class="samp">diff -C 1 lao tzu</span></samp>' (see <a href="#Sample-diff-Input">Sample diff Input</a>, for the complete contents of the two files).  Notice that at
most one context line is reported here.

<pre class="example">     *** lao	2002-02-21 23:30:39.942229878 -0800
     --- tzu	2002-02-21 23:30:50.442260588 -0800
     ***************
     *** 1,5 ****
     - The Way that can be told of is not the eternal Way;
     - The name that can be named is not the eternal name.
       The Nameless is the origin of Heaven and Earth;
     ! The Named is the mother of all things.
       Therefore let there always be non-being,
     --- 1,4 ----
       The Nameless is the origin of Heaven and Earth;
     ! The named is the mother of all things.
     !
       Therefore let there always be non-being,
     ***************
     *** 11 ****
     --- 10,13 ----
         they have different names.
     + They both may be called deep and profound.
     + Deeper and more profound,
     + The door of all subtleties!
</pre>
   <div class="node">
<p><hr>
<a name="Unified-Format"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Sections">Sections</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Context-Format">Context Format</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Context">Context</a>

</div>

<h4 class="subsection">2.3.2 Unified Format</h4>

<p><a name="index-unified-output-format-23"></a><a name="index-g_t_0040samp_007b_002b_002d_007d-output-format-24"></a>
The unified output format is a variation on the context format that is
more compact because it omits redundant context lines.  To select this
output format, use the <samp><span class="option">-U </span><var>lines</var></samp>,
<samp><span class="option">--unified[=</span><var>lines</var><span class="option">]</span></samp>, or <samp><span class="option">-u</span></samp>
option.  The argument <var>lines</var> is the number of lines of context to
show.  When it is not given, it defaults to three.

   <p>At present, only <span class="sc">gnu</span> <samp><span class="command">diff</span></samp> can produce this format and
only <span class="sc">gnu</span> <samp><span class="command">patch</span></samp> can automatically apply diffs in this
format.  For proper operation, <samp><span class="command">patch</span></samp> typically needs at
least three lines of context.

<ul class="menu">
<li><a accesskey="1" href="#Detailed-Unified">Detailed Unified</a>:  A detailed description of unified format. 
<li><a accesskey="2" href="#Example-Unified">Example Unified</a>:   Sample output in unified format. 
</ul>

<div class="node">
<p><hr>
<a name="Detailed-Unified"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Example-Unified">Example Unified</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Unified-Format">Unified Format</a>

</div>

<h5 class="subsubsection">2.3.2.1 Detailed Description of Unified Format</h5>

<p>The unified output format starts with a two-line header, which looks
like this:

<pre class="example">     --- <var>from-file</var> <var>from-file-modification-time</var>
     +++ <var>to-file</var> <var>to-file-modification-time</var>
</pre>
   <p class="noindent"><a name="index-time-stamp-format_002c-unified-diffs-25"></a>The time stamp looks like `<samp><span class="samp">2002-02-21 23:30:39.942229878 -0800</span></samp>'
to indicate the date, time with fractional seconds, and time zone.

   <p>You can change the header's content with the
<samp><span class="option">--label=</span><var>label</var></samp> option; see See <a href="#Alternate-Names">Alternate Names</a>.

   <p>Next come one or more hunks of differences; each hunk shows one area
where the files differ.  Unified format hunks look like this:

<pre class="example">     @@ <var>from-file-range</var> <var>to-file-range</var> @@
      <var>line-from-either-file</var>
      <var>line-from-either-file</var>...
</pre>
   <p>The lines common to both files begin with a space character.  The lines
that actually differ between the two files have one of the following
indicator characters in the left print column:

     <dl>
<dt>`<samp><span class="samp">+</span></samp>'<dd>A line was added here to the first file.

     <br><dt>`<samp><span class="samp">-</span></samp>'<dd>A line was removed here from the first file. 
</dl>

<div class="node">
<p><hr>
<a name="Example-Unified"></a>
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Detailed-Unified">Detailed Unified</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Unified-Format">Unified Format</a>

</div>

<h5 class="subsubsection">2.3.2.2 An Example of Unified Format</h5>

<p>Here is the output of the command `<samp><span class="samp">diff -u lao tzu</span></samp>'
(see <a href="#Sample-diff-Input">Sample diff Input</a>, for the complete contents of the two files):

<pre class="example">     --- lao	2002-02-21 23:30:39.942229878 -0800
     +++ tzu	2002-02-21 23:30:50.442260588 -0800
     @@ -1,7 +1,6 @@
     -The Way that can be told of is not the eternal Way;
     -The name that can be named is not the eternal name.
      The Nameless is the origin of Heaven and Earth;
     -The Named is the mother of all things.
     +The named is the mother of all things.
     +
      Therefore let there always be non-being,
        so we may see their subtlety,
      And let there always be being,
     @@ -9,3 +8,6 @@
      The two are the same,
      But after they are produced,
        they have different names.
     +They both may be called deep and profound.
     +Deeper and more profound,
     +The door of all subtleties!
</pre>
   <div class="node">
<p><hr>
<a name="Sections"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Alternate-Names">Alternate Names</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Unified-Format">Unified Format</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Context">Context</a>

</div>

<h4 class="subsection">2.3.3 Showing Which Sections Differences Are in</h4>

<p><a name="index-headings-26"></a><a name="index-section-headings-27"></a>
Sometimes you might want to know which part of the files each change
falls in.  If the files are source code, this could mean which function
was changed.  If the files are documents, it could mean which chapter or
appendix was changed.  <span class="sc">gnu</span> <samp><span class="command">diff</span></samp> can show this by displaying the
nearest section heading line that precedes the differing lines.  Which
lines are &ldquo;section headings&rdquo; is determined by a regular expression.

<ul class="menu">
<li><a accesskey="1" href="#Specified-Headings">Specified Headings</a>:   Showing headings that match regular expressions. 
<li><a accesskey="2" href="#C-Function-Headings">C Function Headings</a>:  Showing headings of C functions. 
</ul>

<div class="node">
<p><hr>
<a name="Specified-Headings"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#C-Function-Headings">C Function Headings</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Sections">Sections</a>

</div>

<h5 class="subsubsection">2.3.3.1 Showing Lines That Match Regular Expressions</h5>

<p><a name="index-specified-headings-28"></a><a name="index-regular-expression-matching-headings-29"></a>
To show in which sections differences occur for files that are not
source code for C or similar languages, use the <samp><span class="option">-F </span><var>regexp</var></samp>
or <samp><span class="option">--show-function-line=</span><var>regexp</var></samp> option.  <samp><span class="command">diff</span></samp>
considers lines that match the <samp><span class="command">grep</span></samp>-style regular expression
<var>regexp</var> to be the beginning
of a section of the file.  Here are suggested regular expressions for
some common languages:

<!-- Please add to this list, e.g. Fortran, Pascal, Perl, Python. -->
<dl>
<dt>`<samp><span class="samp">^[[:alpha:]$_]</span></samp>'<dd>C, C++, Prolog
<br><dt>`<samp><span class="samp">^(</span></samp>'<dd>Lisp
<br><dt>`<samp><span class="samp">^@node</span></samp>'<dd>Texinfo
</dl>

   <p>This option does not automatically select an output format; in order to
use it, you must select the context format (see <a href="#Context-Format">Context Format</a>) or
unified format (see <a href="#Unified-Format">Unified Format</a>).  In other output formats it
has no effect.

   <p>The <samp><span class="option">-F</span></samp> and <samp><span class="option">--show-function-line</span></samp> options find the nearest
unchanged line that precedes each hunk of differences and matches the
given regular expression.  Then they add that line to the end of the
line of asterisks in the context format, or to the `<samp><span class="samp">@@</span></samp>' line in
unified format.  If no matching line exists, they leave the output for
that hunk unchanged.  If that line is more than 40 characters long, they
output only the first 40 characters.  You can specify more than one
regular expression for such lines; <samp><span class="command">diff</span></samp> tries to match each line
against each regular expression, starting with the last one given.  This
means that you can use <samp><span class="option">-p</span></samp> and <samp><span class="option">-F</span></samp> together, if you wish.

<div class="node">
<p><hr>
<a name="C-Function-Headings"></a>
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Specified-Headings">Specified Headings</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Sections">Sections</a>

</div>

<h5 class="subsubsection">2.3.3.2 Showing C Function Headings</h5>

<p><a name="index-C-function-headings-30"></a><a name="index-function-headings_002c-C-31"></a>
To show in which functions differences occur for C and similar
languages, you can use the <samp><span class="option">-p</span></samp> or <samp><span class="option">--show-c-function</span></samp> option. 
This option automatically defaults to the context output format
(see <a href="#Context-Format">Context Format</a>), with the default number of lines of context. 
You can override that number with <samp><span class="option">-C </span><var>lines</var></samp> elsewhere in the
command line.  You can override both the format and the number with
<samp><span class="option">-U </span><var>lines</var></samp> elsewhere in the command line.

   <p>The <samp><span class="option">-p</span></samp> and <samp><span class="option">--show-c-function</span></samp> options are equivalent to
<samp><span class="option">-F '^[[:alpha:]$_]'</span></samp> if the unified format is specified, otherwise
<samp><span class="option">-c -F '^[[:alpha:]$_]'</span></samp> (see <a href="#Specified-Headings">Specified Headings</a>).  <span class="sc">gnu</span>
<samp><span class="command">diff</span></samp> provides them for the sake of convenience.

<div class="node">
<p><hr>
<a name="Alternate-Names"></a>
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Sections">Sections</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Context">Context</a>

</div>

<h4 class="subsection">2.3.4 Showing Alternate File Names</h4>

<p><a name="index-alternate-file-names-32"></a><a name="index-file-name-alternates-33"></a>
If you are comparing two files that have meaningless or uninformative
names, you might want <samp><span class="command">diff</span></samp> to show alternate names in the header
of the context and unified output formats.  To do this, use the
<samp><span class="option">--label=</span><var>label</var></samp> option.  The first time
you give this option, its argument replaces the name and date of the
first file in the header; the second time, its argument replaces the
name and date of the second file.  If you give this option more than
twice, <samp><span class="command">diff</span></samp> reports an error.  The <samp><span class="option">--label</span></samp> option does not
affect the file names in the <samp><span class="command">pr</span></samp> header when the <samp><span class="option">-l</span></samp> or
<samp><span class="option">--paginate</span></samp> option is used (see <a href="#Pagination">Pagination</a>).

   <p>Here are the first two lines of the output from `<samp><span class="samp">diff -C 2
--label=original --label=modified lao tzu</span></samp>':

<pre class="example">     *** original
     --- modified
</pre>
   <div class="node">
<p><hr>
<a name="Side-by-Side"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Scripts">Scripts</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Context">Context</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Output-Formats">Output Formats</a>

</div>

<h3 class="section">2.4 Showing Differences Side by Side</h3>

<p><a name="index-side-by-side-34"></a><a name="index-two_002dcolumn-output-35"></a><a name="index-columnar-output-36"></a>
<samp><span class="command">diff</span></samp> can produce a side by side difference listing of two files. 
The files are listed in two columns with a gutter between them.  The
gutter contains one of the following markers:

     <dl>
<dt>white space<dd>The corresponding lines are in common.  That is, either the lines are
identical, or the difference is ignored because of one of the
<samp><span class="option">--ignore</span></samp> options (see <a href="#White-Space">White Space</a>).

     <br><dt>`<samp><span class="samp">|</span></samp>'<dd>The corresponding lines differ, and they are either both complete
or both incomplete.

     <br><dt>`<samp><span class="samp">&lt;</span></samp>'<dd>The files differ and only the first file contains the line.

     <br><dt>`<samp><span class="samp">&gt;</span></samp>'<dd>The files differ and only the second file contains the line.

     <br><dt>`<samp><span class="samp">(</span></samp>'<dd>Only the first file contains the line, but the difference is ignored.

     <br><dt>`<samp><span class="samp">)</span></samp>'<dd>Only the second file contains the line, but the difference is ignored.

     <br><dt>`<samp><span class="samp">\</span></samp>'<dd>The corresponding lines differ, and only the first line is incomplete.

     <br><dt>`<samp><span class="samp">/</span></samp>'<dd>The corresponding lines differ, and only the second line is incomplete. 
</dl>

   <p>Normally, an output line is incomplete if and only if the lines that it
contains are incomplete; See <a href="#Incomplete-Lines">Incomplete Lines</a>.  However, when an
output line represents two differing lines, one might be incomplete
while the other is not.  In this case, the output line is complete,
but its the gutter is marked `<samp><span class="samp">\</span></samp>' if the first line is incomplete,
`<samp><span class="samp">/</span></samp>' if the second line is.

   <p>Side by side format is sometimes easiest to read, but it has limitations. 
It generates much wider output than usual, and truncates lines that are
too long to fit.  Also, it relies on lining up output more heavily than
usual, so its output looks particularly bad if you use varying
width fonts, nonstandard tab stops, or nonprinting characters.

   <p>You can use the <samp><span class="command">sdiff</span></samp> command to interactively merge side by side
differences.  See <a href="#Interactive-Merging">Interactive Merging</a>, for more information on merging files.

<ul class="menu">
<li><a accesskey="1" href="#Side-by-Side-Format">Side by Side Format</a>:   Controlling side by side output format. 
<li><a accesskey="2" href="#Example-Side-by-Side">Example Side by Side</a>:  Sample side by side output. 
</ul>

<div class="node">
<p><hr>
<a name="Side-by-Side-Format"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Example-Side-by-Side">Example Side by Side</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Side-by-Side">Side by Side</a>

</div>

<h4 class="subsection">2.4.1 Controlling Side by Side Format</h4>

<p><a name="index-side-by-side-format-37"></a>
The <samp><span class="option">-y</span></samp> or <samp><span class="option">--side-by-side</span></samp> option selects side by side
format.  Because side by side output lines contain two input lines, the
output is wider than usual: normally 130 print columns, which can fit
onto a traditional printer line.  You can set the width of the output
with the <samp><span class="option">-W </span><var>columns</var></samp> or <samp><span class="option">--width=</span><var>columns</var></samp>
option.  The output is split into two halves of equal width, separated by a
small gutter to mark differences; the right half is aligned to a tab
stop so that tabs line up.  Input lines that are too long to fit in half
of an output line are truncated for output.

   <p>The <samp><span class="option">--left-column</span></samp> option prints only the left column of two
common lines.  The <samp><span class="option">--suppress-common-lines</span></samp> option suppresses
common lines entirely.

<div class="node">
<p><hr>
<a name="Example-Side-by-Side"></a>
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Side-by-Side-Format">Side by Side Format</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Side-by-Side">Side by Side</a>

</div>

<h4 class="subsection">2.4.2 An Example of Side by Side Format</h4>

<p>Here is the output of the command `<samp><span class="samp">diff -y -W 72 lao tzu</span></samp>'
(see <a href="#Sample-diff-Input">Sample diff Input</a>, for the complete contents of the two files).

<pre class="example">     The Way that can be told of is n   &lt;
     The name that can be named is no   &lt;
     The Nameless is the origin of He        The Nameless is the origin of He
     The Named is the mother of all t   |    The named is the mother of all t
                                        &gt;
     Therefore let there always be no        Therefore let there always be no
       so we may see their subtlety,           so we may see their subtlety,
     And let there always be being,          And let there always be being,
       so we may see their outcome.            so we may see their outcome.
     The two are the same,                   The two are the same,
     But after they are produced,            But after they are produced,
       they have different names.              they have different names.
                                        &gt;    They both may be called deep and
                                        &gt;    Deeper and more profound,
                                        &gt;    The door of all subtleties!
</pre>
   <div class="node">
<p><hr>
<a name="Scripts"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#If_002dthen_002delse">If-then-else</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Side-by-Side">Side by Side</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Output-Formats">Output Formats</a>

</div>

<h3 class="section">2.5 Making Edit Scripts</h3>

<p><a name="index-script-output-formats-38"></a>
Several output modes produce command scripts for editing <var>from-file</var>
to produce <var>to-file</var>.

<ul class="menu">
<li><a accesskey="1" href="#ed-Scripts">ed Scripts</a>:  Using <samp><span class="command">diff</span></samp> to produce commands for <samp><span class="command">ed</span></samp>. 
<li><a accesskey="2" href="#Forward-ed">Forward ed</a>:  Making forward <samp><span class="command">ed</span></samp> scripts. 
<li><a accesskey="3" href="#RCS">RCS</a>:         A special <samp><span class="command">diff</span></samp> output format used by <span class="sc">rcs</span>. 
</ul>

<div class="node">
<p><hr>
<a name="ed-Scripts"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Forward-ed">Forward ed</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Scripts">Scripts</a>

</div>

<h4 class="subsection">2.5.1 <samp><span class="command">ed</span></samp> Scripts</h4>

<p><a name="index-g_t_0040command_007bed_007d-script-output-format-39"></a>
<samp><span class="command">diff</span></samp> can produce commands that direct the <samp><span class="command">ed</span></samp> text editor
to change the first file into the second file.  Long ago, this was the
only output mode that was suitable for editing one file into another
automatically; today, with <samp><span class="command">patch</span></samp>, it is almost obsolete.  Use the
<samp><span class="option">-e</span></samp> or <samp><span class="option">--ed</span></samp> option to select this output format.

   <p>Like the normal format (see <a href="#Normal">Normal</a>), this output format does not
show any context; unlike the normal format, it does not include the
information necessary to apply the diff in reverse (to produce the first
file if all you have is the second file and the diff).

   <p>If the file <samp><span class="file">d</span></samp> contains the output of `<samp><span class="samp">diff -e old new</span></samp>', then
the command `<samp><span class="samp">(cat d &amp;&amp; echo w) | ed - old</span></samp>' edits <samp><span class="file">old</span></samp> to make
it a copy of <samp><span class="file">new</span></samp>.  More generally, if <samp><span class="file">d1</span></samp>, <samp><span class="file">d2</span></samp>,
<small class="dots">...</small>, <samp><span class="file">dN</span></samp> contain the outputs of `<samp><span class="samp">diff -e old new1</span></samp>',
`<samp><span class="samp">diff -e new1 new2</span></samp>', <small class="dots">...</small>, `<samp><span class="samp">diff -e newN-1 newN</span></samp>',
respectively, then the command `<samp><span class="samp">(cat d1 d2 ... dN &amp;&amp; echo w) |
ed - old</span></samp>' edits <samp><span class="file">old</span></samp> to make it a copy of <samp><span class="file">newN</span></samp>.

<ul class="menu">
<li><a accesskey="1" href="#Detailed-ed">Detailed ed</a>:  A detailed description of <samp><span class="command">ed</span></samp> format. 
<li><a accesskey="2" href="#Example-ed">Example ed</a>:   A sample <samp><span class="command">ed</span></samp> script. 
</ul>

<div class="node">
<p><hr>
<a name="Detailed-ed"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Example-ed">Example ed</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#ed-Scripts">ed Scripts</a>

</div>

<h5 class="subsubsection">2.5.1.1 Detailed Description of <samp><span class="command">ed</span></samp> Format</h5>

<p>The <samp><span class="command">ed</span></samp> output format consists of one or more hunks of
differences.  The changes closest to the ends of the files come first so
that commands that change the number of lines do not affect how
<samp><span class="command">ed</span></samp> interprets line numbers in succeeding commands.  <samp><span class="command">ed</span></samp>
format hunks look like this:

<pre class="example">     <var>change-command</var>
     <var>to-file-line</var>
     <var>to-file-line</var>...
     .
</pre>
   <p>Because <samp><span class="command">ed</span></samp> uses a single period on a line to indicate the end of
input, <span class="sc">gnu</span> <samp><span class="command">diff</span></samp> protects lines of changes that contain a single
period on a line by writing two periods instead, then writing a
subsequent <samp><span class="command">ed</span></samp> command to change the two periods into one.  The
<samp><span class="command">ed</span></samp> format cannot represent an incomplete line, so if the second
file ends in a changed incomplete line, <samp><span class="command">diff</span></samp> reports an error and
then pretends that a newline was appended.

   <p>There are three types of change commands.  Each consists of a line
number or comma-separated range of lines in the first file and a single
character indicating the kind of change to make.  All line numbers are
the original line numbers in the file.  The types of change commands
are:

     <dl>
<dt>`<samp><var>l</var><span class="samp">a</span></samp>'<dd>Add text from the second file after line <var>l</var> in the first file.  For
example, `<samp><span class="samp">8a</span></samp>' means to add the following lines after line 8 of file
1.

     <br><dt>`<samp><var>r</var><span class="samp">c</span></samp>'<dd>Replace the lines in range <var>r</var> in the first file with the following
lines.  Like a combined add and delete, but more compact.  For example,
`<samp><span class="samp">5,7c</span></samp>' means change lines 5&ndash;7 of file 1 to read as the text file
2.

     <br><dt>`<samp><var>r</var><span class="samp">d</span></samp>'<dd>Delete the lines in range <var>r</var> from the first file.  For example,
`<samp><span class="samp">5,7d</span></samp>' means delete lines 5&ndash;7 of file 1. 
</dl>

<div class="node">
<p><hr>
<a name="Example-ed"></a>
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Detailed-ed">Detailed ed</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#ed-Scripts">ed Scripts</a>

</div>

<h5 class="subsubsection">2.5.1.2 Example <samp><span class="command">ed</span></samp> Script</h5>

<p>Here is the output of `<samp><span class="samp">diff -e lao tzu</span></samp>' (see <a href="#Sample-diff-Input">Sample diff Input</a>, for the complete contents of the two files):

<pre class="example">     11a
     They both may be called deep and profound.
     Deeper and more profound,
     The door of all subtleties!
     .
     4c
     The named is the mother of all things.
     
     .
     1,2d
</pre>
   <div class="node">
<p><hr>
<a name="Forward-ed"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#RCS">RCS</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#ed-Scripts">ed Scripts</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Scripts">Scripts</a>

</div>

<h4 class="subsection">2.5.2 Forward <samp><span class="command">ed</span></samp> Scripts</h4>

<p><a name="index-forward-_0040command_007bed_007d-script-output-format-40"></a>
<samp><span class="command">diff</span></samp> can produce output that is like an <samp><span class="command">ed</span></samp> script, but
with hunks in forward (front to back) order.  The format of the commands
is also changed slightly: command characters precede the lines they
modify, spaces separate line numbers in ranges, and no attempt is made
to disambiguate hunk lines consisting of a single period.  Like
<samp><span class="command">ed</span></samp> format, forward <samp><span class="command">ed</span></samp> format cannot represent incomplete
lines.

   <p>Forward <samp><span class="command">ed</span></samp> format is not very useful, because neither <samp><span class="command">ed</span></samp>
nor <samp><span class="command">patch</span></samp> can apply diffs in this format.  It exists mainly for
compatibility with older versions of <samp><span class="command">diff</span></samp>.  Use the <samp><span class="option">-f</span></samp> or
<samp><span class="option">--forward-ed</span></samp> option to select it.

<div class="node">
<p><hr>
<a name="RCS"></a>
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Forward-ed">Forward ed</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Scripts">Scripts</a>

</div>

<h4 class="subsection">2.5.3 <span class="sc">rcs</span> Scripts</h4>

<p><a name="index-g_t_0040sc_007brcs_007d-script-output-format-41"></a>
The <span class="sc">rcs</span> output format is designed specifically for use by the Revision
Control System, which is a set of free programs used for organizing
different versions and systems of files.  Use the <samp><span class="option">-n</span></samp> or
<samp><span class="option">--rcs</span></samp> option to select this output format.  It is like the
forward <samp><span class="command">ed</span></samp> format (see <a href="#Forward-ed">Forward ed</a>), but it can represent
arbitrary changes to the contents of a file because it avoids the
forward <samp><span class="command">ed</span></samp> format's problems with lines consisting of a single
period and with incomplete lines.  Instead of ending text sections with
a line consisting of a single period, each command specifies the number
of lines it affects; a combination of the `<samp><span class="samp">a</span></samp>' and `<samp><span class="samp">d</span></samp>'
commands are used instead of `<samp><span class="samp">c</span></samp>'.  Also, if the second file ends
in a changed incomplete line, then the output also ends in an
incomplete line.

   <p>Here is the output of `<samp><span class="samp">diff -n lao tzu</span></samp>' (see <a href="#Sample-diff-Input">Sample diff Input</a>, for the complete contents of the two files):

<pre class="example">     d1 2
     d4 1
     a4 2
     The named is the mother of all things.
     
     a11 3
     They both may be called deep and profound.
     Deeper and more profound,
     The door of all subtleties!
</pre>
   <div class="node">
<p><hr>
<a name="If-then-else"></a>
<a name="If_002dthen_002delse"></a>
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Scripts">Scripts</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Output-Formats">Output Formats</a>

</div>

<h3 class="section">2.6 Merging Files with If-then-else</h3>

<p><a name="index-merged-output-format-42"></a><a name="index-if_002dthen_002delse-output-format-43"></a><a name="index-C-if_002dthen_002delse-output-format-44"></a><a name="index-g_t_0040command_007bifdef_007d-output-format-45"></a>
You can use <samp><span class="command">diff</span></samp> to merge two files of C source code.  The output
of <samp><span class="command">diff</span></samp> in this format contains all the lines of both files. 
Lines common to both files are output just once; the differing parts are
separated by the C preprocessor directives <code>#ifdef </code><var>name</var> or
<code>#ifndef </code><var>name</var>, <code>#else</code>, and <code>#endif</code>.  When
compiling the output, you select which version to use by either defining
or leaving undefined the macro <var>name</var>.

   <p>To merge two files, use <samp><span class="command">diff</span></samp> with the <samp><span class="option">-D </span><var>name</var></samp> or
<samp><span class="option">--ifdef=</span><var>name</var></samp> option.  The argument <var>name</var> is the C
preprocessor identifier to use in the <code>#ifdef</code> and <code>#ifndef</code>
directives.

   <p>For example, if you change an instance of <code>wait (&amp;s)</code> to
<code>waitpid (-1, &amp;s, 0)</code> and then merge the old and new files with
the <samp><span class="option">--ifdef=HAVE_WAITPID</span></samp> option, then the affected part of your code
might look like this:

<pre class="example">         do {
     #ifndef HAVE_WAITPID
             if ((w = wait (&amp;s)) &lt; 0  &amp;&amp;  errno != EINTR)
     #else /* HAVE_WAITPID */
             if ((w = waitpid (-1, &amp;s, 0)) &lt; 0  &amp;&amp;  errno != EINTR)
     #endif /* HAVE_WAITPID */
                 return w;
         } while (w != child);
</pre>
   <p>You can specify formats for languages other than C by using line group
formats and line formats, as described in the next sections.

<ul class="menu">
<li><a accesskey="1" href="#Line-Group-Formats">Line Group Formats</a>:     Formats for general if-then-else line groups. 
<li><a accesskey="2" href="#Line-Formats">Line Formats</a>:           Formats for each line in a line group. 
<li><a accesskey="3" href="#Detailed-If_002dthen_002delse">Detailed If-then-else</a>:  A detailed description of if-then-else format. 
<li><a accesskey="4" href="#Example-If_002dthen_002delse">Example If-then-else</a>:   Sample if-then-else format output. 
</ul>

<div class="node">
<p><hr>
<a name="Line-Group-Formats"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Line-Formats">Line Formats</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#If_002dthen_002delse">If-then-else</a>

</div>

<h4 class="subsection">2.6.1 Line Group Formats</h4>

<p><a name="index-line-group-formats-46"></a><a name="index-formats-for-if_002dthen_002delse-line-groups-47"></a>
Line group formats let you specify formats suitable for many
applications that allow if-then-else input, including programming
languages and text formatting languages.  A line group format specifies
the output format for a contiguous group of similar lines.

   <p>For example, the following command compares the TeX files <samp><span class="file">old</span></samp>
and <samp><span class="file">new</span></samp>, and outputs a merged file in which old regions are
surrounded by `<samp><span class="samp">\begin{em}</span></samp>'-`<samp><span class="samp">\end{em}</span></samp>' lines, and new
regions are surrounded by `<samp><span class="samp">\begin{bf}</span></samp>'-`<samp><span class="samp">\end{bf}</span></samp>' lines.

<pre class="example">     diff \
        --old-group-format='\begin{em}
     %&lt;\end{em}
     ' \
        --new-group-format='\begin{bf}
     %&gt;\end{bf}
     ' \
        old new
</pre>
   <p>The following command is equivalent to the above example, but it is a
little more verbose, because it spells out the default line group formats.

<pre class="example">     diff \
        --old-group-format='\begin{em}
     %&lt;\end{em}
     ' \
        --new-group-format='\begin{bf}
     %&gt;\end{bf}
     ' \
        --unchanged-group-format='%=' \
        --changed-group-format='\begin{em}
     %&lt;\end{em}
     \begin{bf}
     %&gt;\end{bf}
     ' \
        old new
</pre>
   <p>Here is a more advanced example, which outputs a diff listing with
headers containing line numbers in a &ldquo;plain English&rdquo; style.

<pre class="example">     diff \
        --unchanged-group-format='' \
        --old-group-format='-------- %dn line%(n=1?:s) deleted at %df:
     %&lt;' \
        --new-group-format='-------- %dN line%(N=1?:s) added after %de:
     %&gt;' \
        --changed-group-format='-------- %dn line%(n=1?:s) changed at %df:
     %&lt;-------- to:
     %&gt;' \
        old new
</pre>
   <p>To specify a line group format, use <samp><span class="command">diff</span></samp> with one of the options
listed below.  You can specify up to four line group formats, one for
each kind of line group.  You should quote <var>format</var>, because it
typically contains shell metacharacters.

     <dl>
<dt><samp><span class="option">--old-group-format=</span><var>format</var></samp><dd>These line groups are hunks containing only lines from the first file. 
The default old group format is the same as the changed group format if
it is specified; otherwise it is a format that outputs the line group as-is.

     <br><dt><samp><span class="option">--new-group-format=</span><var>format</var></samp><dd>These line groups are hunks containing only lines from the second
file.  The default new group format is same as the changed group
format if it is specified; otherwise it is a format that outputs the
line group as-is.

     <br><dt><samp><span class="option">--changed-group-format=</span><var>format</var></samp><dd>These line groups are hunks containing lines from both files.  The
default changed group format is the concatenation of the old and new
group formats.

     <br><dt><samp><span class="option">--unchanged-group-format=</span><var>format</var></samp><dd>These line groups contain lines common to both files.  The default
unchanged group format is a format that outputs the line group as-is. 
</dl>

   <p>In a line group format, ordinary characters represent themselves;
conversion specifications start with `<samp><span class="samp">%</span></samp>' and have one of the
following forms.

     <dl>
<dt>`<samp><span class="samp">%&lt;</span></samp>'<dd>stands for the lines from the first file, including the trailing newline. 
Each line is formatted according to the old line format (see <a href="#Line-Formats">Line Formats</a>).

     <br><dt>`<samp><span class="samp">%&gt;</span></samp>'<dd>stands for the lines from the second file, including the trailing newline. 
Each line is formatted according to the new line format.

     <br><dt>`<samp><span class="samp">%=</span></samp>'<dd>stands for the lines common to both files, including the trailing newline. 
Each line is formatted according to the unchanged line format.

     <br><dt>`<samp><span class="samp">%%</span></samp>'<dd>stands for `<samp><span class="samp">%</span></samp>'.

     <br><dt>`<samp><span class="samp">%c'</span><var>C</var><span class="samp">'</span></samp>'<dd>where <var>C</var> is a single character, stands for <var>C</var>. 
<var>C</var> may not be a backslash or an apostrophe. 
For example, `<samp><span class="samp">%c':'</span></samp>' stands for a colon, even inside
the then-part of an if-then-else format, which a colon would
normally terminate.

     <br><dt>`<samp><span class="samp">%c'\</span><var>O</var><span class="samp">'</span></samp>'<dd>where <var>O</var> is a string of 1, 2, or 3 octal digits,
stands for the character with octal code <var>O</var>. 
For example, `<samp><span class="samp">%c'\0'</span></samp>' stands for a null character.

     <br><dt>`<samp><var>F</var><var>n</var></samp>'<dd>where <var>F</var> is a <code>printf</code> conversion specification and <var>n</var> is one
of the following letters, stands for <var>n</var>'s value formatted with <var>F</var>.

          <dl>
<dt>`<samp><span class="samp">e</span></samp>'<dd>The line number of the line just before the group in the old file.

          <br><dt>`<samp><span class="samp">f</span></samp>'<dd>The line number of the first line in the group in the old file;
equals <var>e</var> + 1.

          <br><dt>`<samp><span class="samp">l</span></samp>'<dd>The line number of the last line in the group in the old file.

          <br><dt>`<samp><span class="samp">m</span></samp>'<dd>The line number of the line just after the group in the old file;
equals <var>l</var> + 1.

          <br><dt>`<samp><span class="samp">n</span></samp>'<dd>The number of lines in the group in the old file; equals <var>l</var> - <var>f</var> + 1.

          <br><dt>`<samp><span class="samp">E, F, L, M, N</span></samp>'<dd>Likewise, for lines in the new file.

     </dl>

     <p><a name="index-LC_005fNUMERIC-48"></a>The <code>printf</code> conversion specification can be `<samp><span class="samp">%d</span></samp>',
`<samp><span class="samp">%o</span></samp>', `<samp><span class="samp">%x</span></samp>', or `<samp><span class="samp">%X</span></samp>', specifying decimal, octal,
lower case hexadecimal, or upper case hexadecimal output
respectively.  After the `<samp><span class="samp">%</span></samp>' the following options can appear in
sequence: a series of zero or more flags; an integer
specifying the minimum field width; and a period followed by an
optional integer specifying the minimum number of digits. 
The flags are `<samp><span class="samp">-</span></samp>' for left-justification, `<samp><span class="samp">'</span></samp>' for separating
the digit into groups as specified by the <samp><span class="env">LC_NUMERIC</span></samp> locale category,
and `<samp><span class="samp">0</span></samp>' for padding with zeros instead of spaces. 
For example, `<samp><span class="samp">%5dN</span></samp>' prints the number of new lines in the group
in a field of width 5 characters, using the <code>printf</code> format <code>"%5d"</code>.

     <br><dt>`<samp><span class="samp">(</span><var>A</var><span class="samp">=</span><var>B</var><span class="samp">?</span><var>T</var><span class="samp">:</span><var>E</var><span class="samp">)</span></samp>'<dd>If <var>A</var> equals <var>B</var> then <var>T</var> else <var>E</var>. 
<var>A</var> and <var>B</var> are each either a decimal constant
or a single letter interpreted as above. 
This format spec is equivalent to <var>T</var> if
<var>A</var>'s value equals <var>B</var>'s; otherwise it is equivalent to <var>E</var>.

     <p>For example, `<samp><span class="samp">%(N=0?no:%dN) line%(N=1?:s)</span></samp>' is equivalent to
`<samp><span class="samp">no lines</span></samp>' if <var>N</var> (the number of lines in the group in the the
new file) is 0, to `<samp><span class="samp">1 line</span></samp>' if <var>N</var> is 1, and to `<samp><span class="samp">%dN lines</span></samp>'
otherwise. 
</dl>

<div class="node">
<p><hr>
<a name="Line-Formats"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Detailed-If_002dthen_002delse">Detailed If-then-else</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Line-Group-Formats">Line Group Formats</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#If_002dthen_002delse">If-then-else</a>

</div>

<h4 class="subsection">2.6.2 Line Formats</h4>

<p><a name="index-line-formats-49"></a>
Line formats control how each line taken from an input file is
output as part of a line group in if-then-else format.

   <p>For example, the following command outputs text with a one-character
change indicator to the left of the text.  The first character of output
is `<samp><span class="samp">-</span></samp>' for deleted lines, `<samp><span class="samp">|</span></samp>' for added lines, and a space for
unchanged lines.  The formats contain newline characters where newlines
are desired on output.

<pre class="example">     diff \
        --old-line-format='-%l
     ' \
        --new-line-format='|%l
     ' \
        --unchanged-line-format=' %l
     ' \
        old new
</pre>
   <p>To specify a line format, use one of the following options.  You should
quote <var>format</var>, since it often contains shell metacharacters.

     <dl>
<dt><samp><span class="option">--old-line-format=</span><var>format</var></samp><dd>formats lines just from the first file.

     <br><dt><samp><span class="option">--new-line-format=</span><var>format</var></samp><dd>formats lines just from the second file.

     <br><dt><samp><span class="option">--unchanged-line-format=</span><var>format</var></samp><dd>formats lines common to both files.

     <br><dt><samp><span class="option">--line-format=</span><var>format</var></samp><dd>formats all lines; in effect, it sets all three above options simultaneously. 
</dl>

   <p>In a line format, ordinary characters represent themselves;
conversion specifications start with `<samp><span class="samp">%</span></samp>' and have one of the
following forms.

     <dl>
<dt>`<samp><span class="samp">%l</span></samp>'<dd>stands for the contents of the line, not counting its trailing
newline (if any).  This format ignores whether the line is incomplete;
See <a href="#Incomplete-Lines">Incomplete Lines</a>.

     <br><dt>`<samp><span class="samp">%L</span></samp>'<dd>stands for the contents of the line, including its trailing newline
(if any).  If a line is incomplete, this format preserves its
incompleteness.

     <br><dt>`<samp><span class="samp">%%</span></samp>'<dd>stands for `<samp><span class="samp">%</span></samp>'.

     <br><dt>`<samp><span class="samp">%c'</span><var>C</var><span class="samp">'</span></samp>'<dd>where <var>C</var> is a single character, stands for <var>C</var>. 
<var>C</var> may not be a backslash or an apostrophe. 
For example, `<samp><span class="samp">%c':'</span></samp>' stands for a colon.

     <br><dt>`<samp><span class="samp">%c'\</span><var>O</var><span class="samp">'</span></samp>'<dd>where <var>O</var> is a string of 1, 2, or 3 octal digits,
stands for the character with octal code <var>O</var>. 
For example, `<samp><span class="samp">%c'\0'</span></samp>' stands for a null character.

     <br><dt>`<samp><var>F</var><span class="samp">n</span></samp>'<dd>where <var>F</var> is a <code>printf</code> conversion specification,
stands for the line number formatted with <var>F</var>. 
For example, `<samp><span class="samp">%.5dn</span></samp>' prints the line number using the
<code>printf</code> format <code>"%.5d"</code>.  See <a href="#Line-Group-Formats">Line Group Formats</a>, for
more about printf conversion specifications.

   </dl>

   <p>The default line format is `<samp><span class="samp">%l</span></samp>' followed by a newline character.

   <p>If the input contains tab characters and it is important that they line
up on output, you should ensure that `<samp><span class="samp">%l</span></samp>' or `<samp><span class="samp">%L</span></samp>' in a line
format is just after a tab stop (e.g. by preceding `<samp><span class="samp">%l</span></samp>' or
`<samp><span class="samp">%L</span></samp>' with a tab character), or you should use the <samp><span class="option">-t</span></samp> or
<samp><span class="option">--expand-tabs</span></samp> option.

   <p>Taken together, the line and line group formats let you specify many
different formats.  For example, the following command uses a format
similar to normal <samp><span class="command">diff</span></samp> format.  You can tailor this command
to get fine control over <samp><span class="command">diff</span></samp> output.

<pre class="example">     diff \
        --old-line-format='&lt; %l
     ' \
        --new-line-format='&gt; %l
     ' \
        --old-group-format='%df%(f=l?:,%dl)d%dE
     %&lt;' \
        --new-group-format='%dea%dF%(F=L?:,%dL)
     %&gt;' \
        --changed-group-format='%df%(f=l?:,%dl)c%dF%(F=L?:,%dL)
     %&lt;---
     %&gt;' \
        --unchanged-group-format='' \
        old new
</pre>
   <div class="node">
<p><hr>
<a name="Detailed-If-then-else"></a>
<a name="Detailed-If_002dthen_002delse"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Example-If_002dthen_002delse">Example If-then-else</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Line-Formats">Line Formats</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#If_002dthen_002delse">If-then-else</a>

</div>

<h4 class="subsection">2.6.3 Detailed Description of If-then-else Format</h4>

<p>For lines common to both files, <samp><span class="command">diff</span></samp> uses the unchanged line
group format.  For each hunk of differences in the merged output
format, if the hunk contains only lines from the first file,
<samp><span class="command">diff</span></samp> uses the old line group format; if the hunk contains only
lines from the second file, <samp><span class="command">diff</span></samp> uses the new group format;
otherwise, <samp><span class="command">diff</span></samp> uses the changed group format.

   <p>The old, new, and unchanged line formats specify the output format of
lines from the first file, lines from the second file, and lines common
to both files, respectively.

   <p>The option <samp><span class="option">--ifdef=</span><var>name</var></samp> is equivalent to
the following sequence of options using shell syntax:

<pre class="example">     --old-group-format='#ifndef <var>name</var>
     %&lt;#endif /* ! <var>name</var> */
     ' \
     --new-group-format='#ifdef <var>name</var>
     %&gt;#endif /* <var>name</var> */
     ' \
     --unchanged-group-format='%=' \
     --changed-group-format='#ifndef <var>name</var>
     %&lt;#else /* <var>name</var> */
     %&gt;#endif /* <var>name</var> */
     '
</pre>
   <p>You should carefully check the <samp><span class="command">diff</span></samp> output for proper nesting. 
For example, when using the <samp><span class="option">-D </span><var>name</var></samp> or
<samp><span class="option">--ifdef=</span><var>name</var></samp> option, you should check that if the
differing lines contain any of the C preprocessor directives
`<samp><span class="samp">#ifdef</span></samp>', `<samp><span class="samp">#ifndef</span></samp>', `<samp><span class="samp">#else</span></samp>', `<samp><span class="samp">#elif</span></samp>', or
`<samp><span class="samp">#endif</span></samp>', they are nested properly and match.  If they don't, you
must make corrections manually.  It is a good idea to carefully check
the resulting code anyway to make sure that it really does what you
want it to; depending on how the input files were produced, the output
might contain duplicate or otherwise incorrect code.

   <p>The <samp><span class="command">patch</span></samp> <samp><span class="option">-D </span><var>name</var></samp> option behaves like
the <samp><span class="command">diff</span></samp> <samp><span class="option">-D </span><var>name</var></samp> option, except it operates on
a file and a diff to produce a merged file; See <a href="#patch-Options">patch Options</a>.

<div class="node">
<p><hr>
<a name="Example-If-then-else"></a>
<a name="Example-If_002dthen_002delse"></a>
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Detailed-If_002dthen_002delse">Detailed If-then-else</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#If_002dthen_002delse">If-then-else</a>

</div>

<h4 class="subsection">2.6.4 An Example of If-then-else Format</h4>

<p>Here is the output of `<samp><span class="samp">diff -DTWO lao tzu</span></samp>' (see <a href="#Sample-diff-Input">Sample diff Input</a>, for the complete contents of the two files):

<pre class="example">     #ifndef TWO
     The Way that can be told of is not the eternal Way;
     The name that can be named is not the eternal name.
     #endif /* ! TWO */
     The Nameless is the origin of Heaven and Earth;
     #ifndef TWO
     The Named is the mother of all things.
     #else /* TWO */
     The named is the mother of all things.
     
     #endif /* TWO */
     Therefore let there always be non-being,
       so we may see their subtlety,
     And let there always be being,
       so we may see their outcome.
     The two are the same,
     But after they are produced,
       they have different names.
     #ifdef TWO
     They both may be called deep and profound.
     Deeper and more profound,
     The door of all subtleties!
     #endif /* TWO */
</pre>
   <div class="node">
<p><hr>
<a name="Incomplete-Lines"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Comparing-Directories">Comparing Directories</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Output-Formats">Output Formats</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Top">Top</a>

</div>

<h2 class="chapter">3 Incomplete Lines</h2>

<p><a name="index-incomplete-lines-50"></a><a name="index-full-lines-51"></a><a name="index-newline-treatment-by-_0040command_007bdiff_007d-52"></a>
When an input file ends in a non-newline character, its last line is
called an <dfn>incomplete line</dfn> because its last character is not a
newline.  All other lines are called <dfn>full lines</dfn> and end in a
newline character.  Incomplete lines do not match full lines unless
differences in white space are ignored (see <a href="#White-Space">White Space</a>).

   <p>An incomplete line is normally distinguished on output from a full line
by a following line that starts with `<samp><span class="samp">\</span></samp>'.  However, the <span class="sc">rcs</span> format
(see <a href="#RCS">RCS</a>) outputs the incomplete line as-is, without any trailing
newline or following line.  The side by side format normally represents
incomplete lines as-is, but in some cases uses a `<samp><span class="samp">\</span></samp>' or `<samp><span class="samp">/</span></samp>'
gutter marker; See <a href="#Side-by-Side">Side by Side</a>.  The if-then-else line format
preserves a line's incompleteness with `<samp><span class="samp">%L</span></samp>', and discards the
newline with `<samp><span class="samp">%l</span></samp>'; See <a href="#Line-Formats">Line Formats</a>.  Finally, with the
<samp><span class="command">ed</span></samp> and forward <samp><span class="command">ed</span></samp> output formats (see <a href="#Output-Formats">Output Formats</a>)
<samp><span class="command">diff</span></samp> cannot represent an incomplete line, so it pretends there
was a newline and reports an error.

   <p>For example, suppose <samp><span class="file">F</span></samp> and <samp><span class="file">G</span></samp> are one-byte files that
contain just `<samp><span class="samp">f</span></samp>' and `<samp><span class="samp">g</span></samp>', respectively.  Then `<samp><span class="samp">diff F G</span></samp>'
outputs

<pre class="example">     1c1
     &lt; f
     \ No newline at end of file
     ---
     &gt; g
     \ No newline at end of file
</pre>
   <p class="noindent">(The exact message may differ in non-English locales.) 
`<samp><span class="samp">diff -n F G</span></samp>' outputs the following without a trailing newline:

<pre class="example">     d1 1
     a1 1
     g
</pre>
   <p class="noindent">`<samp><span class="samp">diff -e F G</span></samp>' reports two errors and outputs the following:

<pre class="example">     1c
     g
     .
</pre>
   <div class="node">
<p><hr>
<a name="Comparing-Directories"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Adjusting-Output">Adjusting Output</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Incomplete-Lines">Incomplete Lines</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Top">Top</a>

</div>

<h2 class="chapter">4 Comparing Directories</h2>

<p><a name="index-LC_005fCOLLATE-53"></a>You can use <samp><span class="command">diff</span></samp> to compare some or all of the files in two
directory trees.  When both file name arguments to <samp><span class="command">diff</span></samp> are
directories, it compares each file that is contained in both
directories, examining file names in alphabetical order as specified by
the <samp><span class="env">LC_COLLATE</span></samp> locale category.  Normally
<samp><span class="command">diff</span></samp> is silent about pairs of files that contain no differences,
but if you use the <samp><span class="option">-s</span></samp> or <samp><span class="option">--report-identical-files</span></samp> option,
it reports pairs of identical files.  Normally <samp><span class="command">diff</span></samp> reports
subdirectories common to both directories without comparing
subdirectories' files, but if you use the <samp><span class="option">-r</span></samp> or
<samp><span class="option">--recursive</span></samp> option, it compares every corresponding pair of files
in the directory trees, as many levels deep as they go.

   <p>For file names that are in only one of the directories, <samp><span class="command">diff</span></samp>
normally does not show the contents of the file that exists; it reports
only that the file exists in that directory and not in the other.  You
can make <samp><span class="command">diff</span></samp> act as though the file existed but was empty in the
other directory, so that it outputs the entire contents of the file that
actually exists.  (It is output as either an insertion or a
deletion, depending on whether it is in the first or the second
directory given.)  To do this, use the <samp><span class="option">-N</span></samp> or <samp><span class="option">--new-file</span></samp>
option.

   <p>If the older directory contains one or more large files that are not in
the newer directory, you can make the patch smaller by using the
<samp><span class="option">--unidirectional-new-file</span></samp> option instead of <samp><span class="option">-N</span></samp>. 
This option is like <samp><span class="option">-N</span></samp> except that it only inserts the contents
of files that appear in the second directory but not the first (that is,
files that were added).  At the top of the patch, write instructions for
the user applying the patch to remove the files that were deleted before
applying the patch.  See <a href="#Making-Patches">Making Patches</a>, for more discussion of
making patches for distribution.

   <p>To ignore some files while comparing directories, use the <samp><span class="option">-x
</span><var>pattern</var></samp> or <samp><span class="option">--exclude=</span><var>pattern</var></samp> option.  This option
ignores any files or subdirectories whose base names match the shell
pattern <var>pattern</var>.  Unlike in the shell, a period at the start of
the base of a file name matches a wildcard at the start of a pattern. 
You should enclose <var>pattern</var> in quotes so that the shell does not
expand it.  For example, the option <samp><span class="option">-x '*.[ao]'</span></samp> ignores any file
whose name ends with `<samp><span class="samp">.a</span></samp>' or `<samp><span class="samp">.o</span></samp>'.

   <p>This option accumulates if you specify it more than once.  For example,
using the options <samp><span class="option">-x 'RCS' -x '*,v'</span></samp> ignores any file or
subdirectory whose base name is `<samp><span class="samp">RCS</span></samp>' or ends with `<samp><span class="samp">,v</span></samp>'.

   <p>If you need to give this option many times, you can instead put the
patterns in a file, one pattern per line, and use the <samp><span class="option">-X
</span><var>file</var></samp> or <samp><span class="option">--exclude-from=</span><var>file</var></samp> option.

   <p>If you have been comparing two directories and stopped partway through,
later you might want to continue where you left off.  You can do this by
using the <samp><span class="option">-S </span><var>file</var></samp> or <samp><span class="option">--starting-file=</span><var>file</var></samp>
option.  This compares only the file <var>file</var> and all alphabetically
later files in the topmost directory level.

   <p>If two directories differ only in that file names are lower case in
one directory and upper case in the upper, <samp><span class="command">diff</span></samp> normally
reports many differences because it compares file names in a
case sensitive way.  With the <samp><span class="option">--ignore-file-name-case</span></samp> option,
<samp><span class="command">diff</span></samp> ignores case differences in file names, so that for example
the contents of the file <samp><span class="file">Tao</span></samp> in one directory are compared to
the contents of the file <samp><span class="file">TAO</span></samp> in the other.  The
<samp><span class="option">--no-ignore-file-name-case</span></samp> option cancels the effect of the
<samp><span class="option">--ignore-file-name-case</span></samp> option, reverting to the default
behavior.

   <p>If an <samp><span class="option">-x </span><var>pattern</var></samp>, <samp><span class="option">--exclude=</span><var>pattern</var></samp>,
<samp><span class="option">-X </span><var>file</var></samp>, or <samp><span class="option">--exclude-from=</span><var>file</var></samp> option
is specified while the <samp><span class="option">--ignore-file-name-case</span></samp> option is in
effect, case is ignored when excluding file names matching the
specified patterns.

<div class="node">
<p><hr>
<a name="Adjusting-Output"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#diff-Performance">diff Performance</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Comparing-Directories">Comparing Directories</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Top">Top</a>

</div>

<h2 class="chapter">5 Making <samp><span class="command">diff</span></samp> Output Prettier</h2>

<p><samp><span class="command">diff</span></samp> provides several ways to adjust the appearance of its output. 
These adjustments can be applied to any output format.

<ul class="menu">
<li><a accesskey="1" href="#Tabs">Tabs</a>:        Preserving the alignment of tab stops. 
<li><a accesskey="2" href="#Pagination">Pagination</a>:  Page numbering and time-stamping <samp><span class="command">diff</span></samp> output. 
</ul>

<div class="node">
<p><hr>
<a name="Tabs"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Pagination">Pagination</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Adjusting-Output">Adjusting Output</a>

</div>

<h3 class="section">5.1 Preserving Tab Stop Alignment</h3>

<p><a name="index-tab-stop-alignment-54"></a><a name="index-aligning-tab-stops-55"></a>
The lines of text in some of the <samp><span class="command">diff</span></samp> output formats are preceded
by one or two characters that indicate whether the text is inserted,
deleted, or changed.  The addition of those characters can cause tabs to
move to the next tab stop, throwing off the alignment of columns in the
line.  <span class="sc">gnu</span> <samp><span class="command">diff</span></samp> provides two ways to make tab-aligned columns
line up correctly.

   <p>The first way is to have <samp><span class="command">diff</span></samp> convert all tabs into the correct
number of spaces before outputting them; select this method with the
<samp><span class="option">-t</span></samp> or <samp><span class="option">--expand-tabs</span></samp> option.  <samp><span class="command">diff</span></samp> assumes that
tab stops are set every 8 print columns.  To use this form of output with
<samp><span class="command">patch</span></samp>, you must give <samp><span class="command">patch</span></samp> the <samp><span class="option">-l</span></samp> or
<samp><span class="option">--ignore-white-space</span></samp> option (see <a href="#Changed-White-Space">Changed White Space</a>, for more
information).

   <p>The other method for making tabs line up correctly is to add a tab
character instead of a space after the indicator character at the
beginning of the line.  This ensures that all following tab characters
are in the same position relative to tab stops that they were in the
original files, so that the output is aligned correctly.  Its
disadvantage is that it can make long lines too long to fit on one line
of the screen or the paper.  It also does not work with the unified
output format, which does not have a space character after the change
type indicator character.  Select this method with the <samp><span class="option">-T</span></samp> or
<samp><span class="option">--initial-tab</span></samp> option.

<div class="node">
<p><hr>
<a name="Pagination"></a>
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Tabs">Tabs</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Adjusting-Output">Adjusting Output</a>

</div>

<h3 class="section">5.2 Paginating <samp><span class="command">diff</span></samp> Output</h3>

<p><a name="index-paginating-_0040command_007bdiff_007d-output-56"></a>
It can be convenient to have long output page-numbered and time-stamped. 
The <samp><span class="option">-l</span></samp> and <samp><span class="option">--paginate</span></samp> options do this by sending the
<samp><span class="command">diff</span></samp> output through the <samp><span class="command">pr</span></samp> program.  Here is what the page
header might look like for `<samp><span class="samp">diff -lc lao tzu</span></samp>':

<pre class="example">     2002-02-22 14:20                 diff -lc lao tzu                 Page 1
</pre>
   <div class="node">
<p><hr>
<a name="diff-Performance"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Comparing-Three-Files">Comparing Three Files</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Adjusting-Output">Adjusting Output</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Top">Top</a>

</div>

<h2 class="chapter">6 <samp><span class="command">diff</span></samp> Performance Tradeoffs</h2>

<p><a name="index-performance-of-_0040command_007bdiff_007d-57"></a>
<span class="sc">gnu</span> <samp><span class="command">diff</span></samp> runs quite efficiently; however, in some circumstances
you can cause it to run faster or produce a more compact set of changes.

   <p>One way to improve <samp><span class="command">diff</span></samp> performance is to use hard or
symbolic links to files instead of copies.  This improves performance
because <samp><span class="command">diff</span></samp> normally does not need to read two hard or
symbolic links to the same file, since their contents must be
identical.  For example, suppose you copy a large directory hierarchy,
make a few changes to the copy, and then often use `<samp><span class="samp">diff -r</span></samp>' to
compare the original to the copy.  If the original files are
read-only, you can greatly improve performance by creating the copy
using hard or symbolic links (e.g., with <span class="sc">gnu</span> `<samp><span class="samp">cp -lR</span></samp>' or
`<samp><span class="samp">cp -sR</span></samp>').  Before editing a file in the copy for the first time,
you should break the link and replace it with a regular copy.

   <p>You can also affect the performance of <span class="sc">gnu</span> <samp><span class="command">diff</span></samp> by
giving it options that change the way it compares files. 
Performance has more than one dimension.  These options improve one
aspect of performance at the cost of another, or they improve
performance in some cases while hurting it in others.

   <p>The way that <span class="sc">gnu</span> <samp><span class="command">diff</span></samp> determines which lines have changed always
comes up with a near-minimal set of differences.  Usually it is good
enough for practical purposes.  If the <samp><span class="command">diff</span></samp> output is large, you
might want <samp><span class="command">diff</span></samp> to use a modified algorithm that sometimes
produces a smaller set of differences.  The <samp><span class="option">-d</span></samp> or
<samp><span class="option">--minimal</span></samp> option does this; however, it can also cause
<samp><span class="command">diff</span></samp> to run more slowly than usual, so it is not the default
behavior.

   <p>When the files you are comparing are large and have small groups of
changes scattered throughout them, you can use the
<samp><span class="option">--speed-large-files</span></samp> option to make a different modification to
the algorithm that <samp><span class="command">diff</span></samp> uses.  If the input files have a constant
small density of changes, this option speeds up the comparisons without
changing the output.  If not, <samp><span class="command">diff</span></samp> might produce a larger set of
differences; however, the output will still be correct.

   <p>Normally <samp><span class="command">diff</span></samp> discards the prefix and suffix that is common to
both files before it attempts to find a minimal set of differences. 
This makes <samp><span class="command">diff</span></samp> run faster, but occasionally it may produce
non-minimal output.  The <samp><span class="option">--horizon-lines=</span><var>lines</var></samp> option
prevents <samp><span class="command">diff</span></samp> from discarding the last <var>lines</var> lines of the
prefix and the first <var>lines</var> lines of the suffix.  This gives
<samp><span class="command">diff</span></samp> further opportunities to find a minimal output.

   <p>Suppose a run of changed lines includes a sequence of lines at one end
and there is an identical sequence of lines just outside the other end. 
The <samp><span class="command">diff</span></samp> command is free to choose which identical sequence is
included in the hunk.  In this case, <samp><span class="command">diff</span></samp> normally shifts the
hunk's boundaries when this merges adjacent hunks, or shifts a hunk's
lines towards the end of the file.  Merging hunks can make the output
look nicer in some cases.

<div class="node">
<p><hr>
<a name="Comparing-Three-Files"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#diff3-Merging">diff3 Merging</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#diff-Performance">diff Performance</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Top">Top</a>

</div>

<h2 class="chapter">7 Comparing Three Files</h2>

<p><a name="index-comparing-three-files-58"></a><a name="index-format-of-_0040command_007bdiff3_007d-output-59"></a>
Use the program <samp><span class="command">diff3</span></samp> to compare three files and show any
differences among them.  (<samp><span class="command">diff3</span></samp> can also merge files; see
<a href="#diff3-Merging">diff3 Merging</a>).

   <p>The &ldquo;normal&rdquo; <samp><span class="command">diff3</span></samp> output format shows each hunk of
differences without surrounding context.  Hunks are labeled depending
on whether they are two-way or three-way, and lines are annotated by
their location in the input files.

   <p>See <a href="#Invoking-diff3">Invoking diff3</a>, for more information on how to run <samp><span class="command">diff3</span></samp>.

<ul class="menu">
<li><a accesskey="1" href="#Sample-diff3-Input">Sample diff3 Input</a>:     Sample <samp><span class="command">diff3</span></samp> input for examples. 
<li><a accesskey="2" href="#Detailed-diff3-Normal">Detailed diff3 Normal</a>:  A detailed description of normal output format. 
<li><a accesskey="3" href="#diff3-Hunks">diff3 Hunks</a>:            The format of normal output format. 
<li><a accesskey="4" href="#Example-diff3-Normal">Example diff3 Normal</a>:   Sample output in the normal format. 
</ul>

<div class="node">
<p><hr>
<a name="Sample-diff3-Input"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Detailed-diff3-Normal">Detailed diff3 Normal</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Comparing-Three-Files">Comparing Three Files</a>

</div>

<h3 class="section">7.1 A Third Sample Input File</h3>

<p><a name="index-g_t_0040command_007bdiff3_007d-sample-input-60"></a><a name="index-sample-input-for-_0040command_007bdiff3_007d-61"></a>
Here is a third sample file that will be used in examples to illustrate
the output of <samp><span class="command">diff3</span></samp> and how various options can change it.  The
first two files are the same that we used for <samp><span class="command">diff</span></samp> (see <a href="#Sample-diff-Input">Sample diff Input</a>).  This is the third sample file, called <samp><span class="file">tao</span></samp>:

<pre class="example">     The Way that can be told of is not the eternal Way;
     The name that can be named is not the eternal name.
     The Nameless is the origin of Heaven and Earth;
     The named is the mother of all things.
     
     Therefore let there always be non-being,
       so we may see their subtlety,
     And let there always be being,
       so we may see their result.
     The two are the same,
     But after they are produced,
       they have different names.
     
       -- The Way of Lao-Tzu, tr. Wing-tsit Chan
</pre>
   <div class="node">
<p><hr>
<a name="Detailed-diff3-Normal"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#diff3-Hunks">diff3 Hunks</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Sample-diff3-Input">Sample diff3 Input</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Comparing-Three-Files">Comparing Three Files</a>

</div>

<h3 class="section">7.2 Detailed Description of <samp><span class="command">diff3</span></samp> Normal Format</h3>

<p>Each hunk begins with a line marked `<samp><span class="samp">====</span></samp>'.  Three-way hunks have
plain `<samp><span class="samp">====</span></samp>' lines, and two-way hunks have `<samp><span class="samp">1</span></samp>', `<samp><span class="samp">2</span></samp>', or
`<samp><span class="samp">3</span></samp>' appended to specify which of the three input files differ in
that hunk.  The hunks contain copies of two or three sets of input
lines each preceded by one or two commands identifying where the lines
came from.

   <p>Normally, two spaces precede each copy of an input line to distinguish
it from the commands.  But with the <samp><span class="option">-T</span></samp> or <samp><span class="option">--initial-tab</span></samp>
option, <samp><span class="command">diff3</span></samp> uses a tab instead of two spaces; this lines up
tabs correctly.  See <a href="#Tabs">Tabs</a>, for more information.

   <p>Commands take the following forms:

     <dl>
<dt>`<samp><var>file</var><span class="samp">:</span><var>l</var><span class="samp">a</span></samp>'<dd>This hunk appears after line <var>l</var> of file <var>file</var>, and
contains no lines in that file.  To edit this file to yield the other
files, one must append hunk lines taken from the other files.  For
example, `<samp><span class="samp">1:11a</span></samp>' means that the hunk follows line 11 in the first
file and contains no lines from that file.

     <br><dt>`<samp><var>file</var><span class="samp">:</span><var>r</var><span class="samp">c</span></samp>'<dd>This hunk contains the lines in the range <var>r</var> of file <var>file</var>. 
The range <var>r</var> is a comma-separated pair of line numbers, or just one
number if the range is a singleton.  To edit this file to yield the
other files, one must change the specified lines to be the lines taken
from the other files.  For example, `<samp><span class="samp">2:11,13c</span></samp>' means that the hunk
contains lines 11 through 13 from the second file. 
</dl>

   <p>If the last line in a set of input lines is incomplete
(see <a href="#Incomplete-Lines">Incomplete Lines</a>), it is distinguished on output from a full
line by a following line that starts with `<samp><span class="samp">\</span></samp>'.

<div class="node">
<p><hr>
<a name="diff3-Hunks"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Example-diff3-Normal">Example diff3 Normal</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Detailed-diff3-Normal">Detailed diff3 Normal</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Comparing-Three-Files">Comparing Three Files</a>

</div>

<h3 class="section">7.3 <samp><span class="command">diff3</span></samp> Hunks</h3>

<p><a name="index-hunks-for-_0040command_007bdiff3_007d-62"></a><a name="index-g_t_0040command_007bdiff3_007d-hunks-63"></a>
Groups of lines that differ in two or three of the input files are
called <dfn>diff3 hunks</dfn>, by analogy with <samp><span class="command">diff</span></samp> hunks
(see <a href="#Hunks">Hunks</a>).  If all three input files differ in a <samp><span class="command">diff3</span></samp>
hunk, the hunk is called a <dfn>three-way hunk</dfn>; if just two input files
differ, it is a <dfn>two-way hunk</dfn>.

   <p>As with <samp><span class="command">diff</span></samp>, several solutions are possible.  When comparing the
files `<samp><span class="samp">A</span></samp>', `<samp><span class="samp">B</span></samp>', and `<samp><span class="samp">C</span></samp>', <samp><span class="command">diff3</span></samp> normally finds
<samp><span class="command">diff3</span></samp> hunks by merging the two-way hunks output by the two
commands `<samp><span class="samp">diff A B</span></samp>' and `<samp><span class="samp">diff A C</span></samp>'.  This does not necessarily
minimize the size of the output, but exceptions should be rare.

   <p>For example, suppose <samp><span class="file">F</span></samp> contains the three lines `<samp><span class="samp">a</span></samp>',
`<samp><span class="samp">b</span></samp>', `<samp><span class="samp">f</span></samp>', <samp><span class="file">G</span></samp> contains the lines `<samp><span class="samp">g</span></samp>', `<samp><span class="samp">b</span></samp>',
`<samp><span class="samp">g</span></samp>', and <samp><span class="file">H</span></samp> contains the lines `<samp><span class="samp">a</span></samp>', `<samp><span class="samp">b</span></samp>',
`<samp><span class="samp">h</span></samp>'.  `<samp><span class="samp">diff3 F G H</span></samp>' might output the following:

<pre class="example">     ====2
     1:1c
     3:1c
       a
     2:1c
       g
     ====
     1:3c
       f
     2:3c
       g
     3:3c
       h
</pre>
   <p class="noindent">because it found a two-way hunk containing `<samp><span class="samp">a</span></samp>' in the first and
third files and `<samp><span class="samp">g</span></samp>' in the second file, then the single line
`<samp><span class="samp">b</span></samp>' common to all three files, then a three-way hunk containing
the last line of each file.

<div class="node">
<p><hr>
<a name="Example-diff3-Normal"></a>
Previous:&nbsp;<a rel="previous" accesskey="p" href="#diff3-Hunks">diff3 Hunks</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Comparing-Three-Files">Comparing Three Files</a>

</div>

<h3 class="section">7.4 An Example of <samp><span class="command">diff3</span></samp> Normal Format</h3>

<p>Here is the output of the command `<samp><span class="samp">diff3 lao tzu tao</span></samp>'
(see <a href="#Sample-diff3-Input">Sample diff3 Input</a>, for the complete contents of the files). 
Notice that it shows only the lines that are different among the three
files.

<pre class="example">     ====2
     1:1,2c
     3:1,2c
       The Way that can be told of is not the eternal Way;
       The name that can be named is not the eternal name.
     2:0a
     ====1
     1:4c
       The Named is the mother of all things.
     2:2,3c
     3:4,5c
       The named is the mother of all things.
     
     ====3
     1:8c
     2:7c
         so we may see their outcome.
     3:9c
         so we may see their result.
     ====
     1:11a
     2:11,13c
       They both may be called deep and profound.
       Deeper and more profound,
       The door of all subtleties!
     3:13,14c
     
         -- The Way of Lao-Tzu, tr. Wing-tsit Chan
</pre>
   <div class="node">
<p><hr>
<a name="diff3-Merging"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Interactive-Merging">Interactive Merging</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Comparing-Three-Files">Comparing Three Files</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Top">Top</a>

</div>

<h2 class="chapter">8 Merging From a Common Ancestor</h2>

<p><a name="index-merging-from-a-common-ancestor-64"></a>
When two people have made changes to copies of the same file,
<samp><span class="command">diff3</span></samp> can produce a merged output that contains both sets of
changes together with warnings about conflicts.

   <p>One might imagine programs with names like <samp><span class="command">diff4</span></samp> and <samp><span class="command">diff5</span></samp>
to compare more than three files simultaneously, but in practice the
need rarely arises.  You can use <samp><span class="command">diff3</span></samp> to merge three or more
sets of changes to a file by merging two change sets at a time.

   <p><samp><span class="command">diff3</span></samp> can incorporate changes from two modified versions into a
common preceding version.  This lets you merge the sets of changes
represented by the two newer files.  Specify the common ancestor version
as the second argument and the two newer versions as the first and third
arguments, like this:

<pre class="example">     diff3 <var>mine</var> <var>older</var> <var>yours</var>
</pre>
   <p class="noindent">You can remember the order of the arguments by noting that they are in
alphabetical order.

   <p><a name="index-conflict-65"></a><a name="index-overlap-66"></a>You can think of this as subtracting <var>older</var> from <var>yours</var> and
adding the result to <var>mine</var>, or as merging into <var>mine</var> the
changes that would turn <var>older</var> into <var>yours</var>.  This merging is
well-defined as long as <var>mine</var> and <var>older</var> match in the
neighborhood of each such change.  This fails to be true when all three
input files differ or when only <var>older</var> differs; we call this
a <dfn>conflict</dfn>.  When all three input files differ, we call the
conflict an <dfn>overlap</dfn>.

   <p><samp><span class="command">diff3</span></samp> gives you several ways to handle overlaps and conflicts. 
You can omit overlaps or conflicts, or select only overlaps,
or mark conflicts with special `<samp><span class="samp">&lt;&lt;&lt;&lt;&lt;&lt;&lt;</span></samp>' and `<samp><span class="samp">&gt;&gt;&gt;&gt;&gt;&gt;&gt;</span></samp>' lines.

   <p><samp><span class="command">diff3</span></samp> can output the merge results as an <samp><span class="command">ed</span></samp> script that
that can be applied to the first file to yield the merged output. 
However, it is usually better to have <samp><span class="command">diff3</span></samp> generate the merged
output directly; this bypasses some problems with <samp><span class="command">ed</span></samp>.

<ul class="menu">
<li><a accesskey="1" href="#Which-Changes">Which Changes</a>:             Selecting changes to incorporate. 
<li><a accesskey="2" href="#Marking-Conflicts">Marking Conflicts</a>:         Marking conflicts. 
<li><a accesskey="3" href="#Bypassing-ed">Bypassing ed</a>:              Generating merged output directly. 
<li><a accesskey="4" href="#Merging-Incomplete-Lines">Merging Incomplete Lines</a>:  How <samp><span class="command">diff3</span></samp> merges incomplete lines. 
<li><a accesskey="5" href="#Saving-the-Changed-File">Saving the Changed File</a>:   Emulating System V behavior. 
</ul>

<div class="node">
<p><hr>
<a name="Which-Changes"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Marking-Conflicts">Marking Conflicts</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#diff3-Merging">diff3 Merging</a>

</div>

<h3 class="section">8.1 Selecting Which Changes to Incorporate</h3>

<p><a name="index-overlapping-change_002c-selection-of-67"></a><a name="index-unmerged-change-68"></a>
You can select all unmerged changes from <var>older</var> to <var>yours</var> for merging
into <var>mine</var> with the <samp><span class="option">-e</span></samp> or <samp><span class="option">--ed</span></samp> option.  You can
select only the nonoverlapping unmerged changes with <samp><span class="option">-3</span></samp> or
<samp><span class="option">--easy-only</span></samp>, and you can select only the overlapping changes with
<samp><span class="option">-x</span></samp> or <samp><span class="option">--overlap-only</span></samp>.

   <p>The <samp><span class="option">-e</span></samp>, <samp><span class="option">-3</span></samp> and <samp><span class="option">-x</span></samp> options select only
<dfn>unmerged changes</dfn>, i.e. changes where <var>mine</var> and <var>yours</var>
differ; they ignore changes from <var>older</var> to <var>yours</var> where
<var>mine</var> and <var>yours</var> are identical, because they assume that such
changes have already been merged.  If this assumption is not a safe
one, you can use the <samp><span class="option">-A</span></samp> or <samp><span class="option">--show-all</span></samp> option
(see <a href="#Marking-Conflicts">Marking Conflicts</a>).

   <p>Here is the output of the command <samp><span class="command">diff3</span></samp> with each of these three
options (see <a href="#Sample-diff3-Input">Sample diff3 Input</a>, for the complete contents of the files). 
Notice that <samp><span class="option">-e</span></samp> outputs the union of the disjoint sets of changes
output by <samp><span class="option">-3</span></samp> and <samp><span class="option">-x</span></samp>.

   <p>Output of `<samp><span class="samp">diff3 -e lao tzu tao</span></samp>':
<pre class="example">     11a
     
       -- The Way of Lao-Tzu, tr. Wing-tsit Chan
     .
     8c
       so we may see their result.
     .
</pre>
   <p>Output of `<samp><span class="samp">diff3 -3 lao tzu tao</span></samp>':
<pre class="example">     8c
       so we may see their result.
     .
</pre>
   <p>Output of `<samp><span class="samp">diff3 -x lao tzu tao</span></samp>':
<pre class="example">     11a
     
       -- The Way of Lao-Tzu, tr. Wing-tsit Chan
     .
</pre>
   <div class="node">
<p><hr>
<a name="Marking-Conflicts"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Bypassing-ed">Bypassing ed</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Which-Changes">Which Changes</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#diff3-Merging">diff3 Merging</a>

</div>

<h3 class="section">8.2 Marking Conflicts</h3>

<p><a name="index-conflict-marking-69"></a><a name="index-g_t_0040samp_007b_003c_003c_003c_003c_003c_003c_003c_007d-for-marking-conflicts-70"></a>
<samp><span class="command">diff3</span></samp> can mark conflicts in the merged output by
bracketing them with special marker lines.  A conflict
that comes from two files <var>A</var> and <var>B</var> is marked as follows:

<pre class="example">     &lt;&lt;&lt;&lt;&lt;&lt;&lt; <var>A</var>
     <span class="roman">lines from </span><var>A</var>
     =======
     <span class="roman">lines from </span><var>B</var>
     &gt;&gt;&gt;&gt;&gt;&gt;&gt; <var>B</var>
</pre>
   <p>A conflict that comes from three files <var>A</var>, <var>B</var> and <var>C</var> is
marked as follows:

<pre class="example">     &lt;&lt;&lt;&lt;&lt;&lt;&lt; <var>A</var>
     <span class="roman">lines from </span><var>A</var>
     ||||||| <var>B</var>
     <span class="roman">lines from </span><var>B</var>
     =======
     <span class="roman">lines from </span><var>C</var>
     &gt;&gt;&gt;&gt;&gt;&gt;&gt; <var>C</var>
</pre>
   <p>The <samp><span class="option">-A</span></samp> or <samp><span class="option">--show-all</span></samp> option acts like the <samp><span class="option">-e</span></samp>
option, except that it brackets conflicts, and it outputs all changes
from <var>older</var> to <var>yours</var>, not just the unmerged changes.  Thus,
given the sample input files (see <a href="#Sample-diff3-Input">Sample diff3 Input</a>), `<samp><span class="samp">diff3
-A lao tzu tao</span></samp>' puts brackets around the conflict where only <samp><span class="file">tzu</span></samp>
differs:

<pre class="example">     &lt;&lt;&lt;&lt;&lt;&lt;&lt; tzu
     =======
     The Way that can be told of is not the eternal Way;
     The name that can be named is not the eternal name.
     &gt;&gt;&gt;&gt;&gt;&gt;&gt; tao
</pre>
   <p>And it outputs the three-way conflict as follows:

<pre class="example">     &lt;&lt;&lt;&lt;&lt;&lt;&lt; lao
     ||||||| tzu
     They both may be called deep and profound.
     Deeper and more profound,
     The door of all subtleties!
     =======
     
       -- The Way of Lao-Tzu, tr. Wing-tsit Chan
     &gt;&gt;&gt;&gt;&gt;&gt;&gt; tao
</pre>
   <p>The <samp><span class="option">-E</span></samp> or <samp><span class="option">--show-overlap</span></samp> option outputs less information
than the <samp><span class="option">-A</span></samp> or <samp><span class="option">--show-all</span></samp> option, because it outputs only
unmerged changes, and it never outputs the contents of the second
file.  Thus the <samp><span class="option">-E</span></samp> option acts like the <samp><span class="option">-e</span></samp> option,
except that it brackets the first and third files from three-way
overlapping changes.  Similarly, <samp><span class="option">-X</span></samp> acts like <samp><span class="option">-x</span></samp>, except
it brackets all its (necessarily overlapping) changes.  For example,
for the three-way overlapping change above, the <samp><span class="option">-E</span></samp> and <samp><span class="option">-X</span></samp>
options output the following:

<pre class="example">     &lt;&lt;&lt;&lt;&lt;&lt;&lt; lao
     =======
     
       -- The Way of Lao-Tzu, tr. Wing-tsit Chan
     &gt;&gt;&gt;&gt;&gt;&gt;&gt; tao
</pre>
   <p>If you are comparing files that have meaningless or uninformative names,
you can use the <samp><span class="option">-L </span><var>label</var></samp> or <samp><span class="option">--label=</span><var>label</var></samp>
option to show alternate names in the `<samp><span class="samp">&lt;&lt;&lt;&lt;&lt;&lt;&lt;</span></samp>', `<samp><span class="samp">|||||||</span></samp>'
and `<samp><span class="samp">&gt;&gt;&gt;&gt;&gt;&gt;&gt;</span></samp>' brackets.  This option can be given up to three
times, once for each input file.  Thus `<samp><span class="samp">diff3 -A -L X -L Y -L Z A
B C</span></samp>' acts like `<samp><span class="samp">diff3 -A A B C</span></samp>', except that the output looks like
it came from files named `<samp><span class="samp">X</span></samp>', `<samp><span class="samp">Y</span></samp>' and `<samp><span class="samp">Z</span></samp>' rather than
from files named `<samp><span class="samp">A</span></samp>', `<samp><span class="samp">B</span></samp>' and `<samp><span class="samp">C</span></samp>'.

<div class="node">
<p><hr>
<a name="Bypassing-ed"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Merging-Incomplete-Lines">Merging Incomplete Lines</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Marking-Conflicts">Marking Conflicts</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#diff3-Merging">diff3 Merging</a>

</div>

<h3 class="section">8.3 Generating the Merged Output Directly</h3>

<p><a name="index-merged-_0040command_007bdiff3_007d-format-71"></a>
With the <samp><span class="option">-m</span></samp> or <samp><span class="option">--merge</span></samp> option, <samp><span class="command">diff3</span></samp> outputs the
merged file directly.  This is more efficient than using <samp><span class="command">ed</span></samp> to
generate it, and works even with non-text files that <samp><span class="command">ed</span></samp> would
reject.  If you specify <samp><span class="option">-m</span></samp> without an <samp><span class="command">ed</span></samp> script option,
<samp><span class="option">-A</span></samp> (<samp><span class="option">--show-all</span></samp>) is assumed.

   <p>For example, the command `<samp><span class="samp">diff3 -m lao tzu tao</span></samp>'
(see <a href="#Sample-diff3-Input">Sample diff3 Input</a> for a copy of the input files) would output
the following:

<pre class="example">     &lt;&lt;&lt;&lt;&lt;&lt;&lt; tzu
     =======
     The Way that can be told of is not the eternal Way;
     The name that can be named is not the eternal name.
     &gt;&gt;&gt;&gt;&gt;&gt;&gt; tao
     The Nameless is the origin of Heaven and Earth;
     The Named is the mother of all things.
     Therefore let there always be non-being,
       so we may see their subtlety,
     And let there always be being,
       so we may see their result.
     The two are the same,
     But after they are produced,
       they have different names.
     &lt;&lt;&lt;&lt;&lt;&lt;&lt; lao
     ||||||| tzu
     They both may be called deep and profound.
     Deeper and more profound,
     The door of all subtleties!
     =======
     
       -- The Way of Lao-Tzu, tr. Wing-tsit Chan
     &gt;&gt;&gt;&gt;&gt;&gt;&gt; tao
</pre>
   <div class="node">
<p><hr>
<a name="Merging-Incomplete-Lines"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Saving-the-Changed-File">Saving the Changed File</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Bypassing-ed">Bypassing ed</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#diff3-Merging">diff3 Merging</a>

</div>

<h3 class="section">8.4 How <samp><span class="command">diff3</span></samp> Merges Incomplete Lines</h3>

<p><a name="index-incomplete-line-merging-72"></a>
With <samp><span class="option">-m</span></samp>, incomplete lines (see <a href="#Incomplete-Lines">Incomplete Lines</a>) are simply
copied to the output as they are found; if the merged output ends in an
conflict and one of the input files ends in an incomplete
line, succeeding `<samp><span class="samp">|||||||</span></samp>', `<samp><span class="samp">=======</span></samp>' or `<samp><span class="samp">&gt;&gt;&gt;&gt;&gt;&gt;&gt;</span></samp>'
brackets appear somewhere other than the start of a line because
they are appended to the incomplete line.

   <p>Without <samp><span class="option">-m</span></samp>, if an <samp><span class="command">ed</span></samp> script option is specified and an
incomplete line is found, <samp><span class="command">diff3</span></samp> generates a warning and acts as
if a newline had been present.

<div class="node">
<p><hr>
<a name="Saving-the-Changed-File"></a>
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Merging-Incomplete-Lines">Merging Incomplete Lines</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#diff3-Merging">diff3 Merging</a>

</div>

<h3 class="section">8.5 Saving the Changed File</h3>

<p><a name="index-System-V-_0040command_007bdiff3_007d-compatibility-73"></a>
Traditional Unix <samp><span class="command">diff3</span></samp> generates an <samp><span class="command">ed</span></samp> script without the
trailing `<samp><span class="samp">w</span></samp>' and `<samp><span class="samp">q</span></samp>' commands that save the changes. 
System V <samp><span class="command">diff3</span></samp> generates these extra commands.  <span class="sc">gnu</span>
<samp><span class="command">diff3</span></samp> normally behaves like traditional Unix
<samp><span class="command">diff3</span></samp>, but with the <samp><span class="option">-i</span></samp> option it behaves like
System V <samp><span class="command">diff3</span></samp> and appends the `<samp><span class="samp">w</span></samp>' and `<samp><span class="samp">q</span></samp>'
commands.

   <p>The <samp><span class="option">-i</span></samp> option requires one of the <samp><span class="command">ed</span></samp> script options
<samp><span class="option">-AeExX3</span></samp>, and is incompatible with the merged output option
<samp><span class="option">-m</span></samp>.

<div class="node">
<p><hr>
<a name="Interactive-Merging"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Merging-with-patch">Merging with patch</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#diff3-Merging">diff3 Merging</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Top">Top</a>

</div>

<h2 class="chapter">9 Interactive Merging with <samp><span class="command">sdiff</span></samp></h2>

<p><a name="index-diff-merging-74"></a><a name="index-interactive-merging-75"></a>
With <samp><span class="command">sdiff</span></samp>, you can merge two files interactively based on a
side-by-side <samp><span class="option">-y</span></samp> format comparison (see <a href="#Side-by-Side">Side by Side</a>).  Use
<samp><span class="option">-o </span><var>file</var></samp> or <samp><span class="option">--output=</span><var>file</var></samp> to specify where to
put the merged text.  See <a href="#Invoking-sdiff">Invoking sdiff</a>, for more details on the
options to <samp><span class="command">sdiff</span></samp>.

   <p>Another way to merge files interactively is to use the Emacs Lisp
package <samp><span class="command">emerge</span></samp>.  See <a href="emacs.html#emerge">emerge</a>, for more information.

<ul class="menu">
<li><a accesskey="1" href="#sdiff-Option-Summary">sdiff Option Summary</a>:  Summary of <samp><span class="command">sdiff</span></samp> options. 
<li><a accesskey="2" href="#Merge-Commands">Merge Commands</a>:        Merging two files interactively. 
</ul>

<div class="node">
<p><hr>
<a name="sdiff-Option-Summary"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Merge-Commands">Merge Commands</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Interactive-Merging">Interactive Merging</a>

</div>

<h3 class="section">9.1 Specifying <samp><span class="command">diff</span></samp> Options to <samp><span class="command">sdiff</span></samp></h3>

<p><a name="index-g_t_0040command_007bsdiff_007d-output-format-76"></a>
The following <samp><span class="command">sdiff</span></samp> options have the same meaning as for
<samp><span class="command">diff</span></samp>.  See <a href="#diff-Options">diff Options</a>, for the use of these options.

<pre class="example">     -a -b -d -i -t -v
     -B -E -I <var>regexp</var>
     
     --ignore-blank-lines  --ignore-case
     --ignore-matching-lines=<var>regexp</var>  --ignore-space-change
     --ignore-tab-expansion
     --left-column  --minimal  --speed-large-files
     --strip-trailing-cr  --suppress-common-lines  --expand-tabs
     --text  --version  --width=<var>columns</var>
</pre>
   <p>For historical reasons, <samp><span class="command">sdiff</span></samp> has alternate names for some
options.  The <samp><span class="option">-l</span></samp> option is equivalent to the
<samp><span class="option">--left-column</span></samp> option, and similarly <samp><span class="option">-s</span></samp> is equivalent
to <samp><span class="option">--suppress-common-lines</span></samp>.  The meaning of the <samp><span class="command">sdiff</span></samp>
<samp><span class="option">-w</span></samp> and <samp><span class="option">-W</span></samp> options is interchanged from that of
<samp><span class="command">diff</span></samp>: with <samp><span class="command">sdiff</span></samp>, <samp><span class="option">-w </span><var>columns</var></samp> is
equivalent to <samp><span class="option">--width=</span><var>columns</var></samp>, and <samp><span class="option">-W</span></samp> is
equivalent to <samp><span class="option">--ignore-all-space</span></samp>.  <samp><span class="command">sdiff</span></samp> without the
<samp><span class="option">-o</span></samp> option is equivalent to <samp><span class="command">diff</span></samp> with the <samp><span class="option">-y</span></samp>
or <samp><span class="option">--side-by-side</span></samp> option (see <a href="#Side-by-Side">Side by Side</a>).

<div class="node">
<p><hr>
<a name="Merge-Commands"></a>
Previous:&nbsp;<a rel="previous" accesskey="p" href="#sdiff-Option-Summary">sdiff Option Summary</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Interactive-Merging">Interactive Merging</a>

</div>

<h3 class="section">9.2 Merge Commands</h3>

<p><a name="index-merge-commands-77"></a><a name="index-merging-interactively-78"></a>
Groups of common lines, with a blank gutter, are copied from the first
file to the output.  After each group of differing lines, <samp><span class="command">sdiff</span></samp>
prompts with `<samp><span class="samp">%</span></samp>' and pauses, waiting for one of the following
commands.  Follow each command with &lt;RET&gt;.

     <dl>
<dt>`<samp><span class="samp">e</span></samp>'<dd>Discard both versions. 
Invoke a text editor on an empty temporary file,
then copy the resulting file to the output.

     <br><dt>`<samp><span class="samp">eb</span></samp>'<dd>Concatenate the two versions, edit the result in a temporary file,
then copy the edited result to the output.

     <br><dt>`<samp><span class="samp">ed</span></samp>'<dd>Like `<samp><span class="samp">eb</span></samp>', except precede each version with a header that
shows what file and lines the version came from.

     <br><dt>`<samp><span class="samp">el</span></samp>'<dd>Edit a copy of the left version, then copy the result to the output.

     <br><dt>`<samp><span class="samp">er</span></samp>'<dd>Edit a copy of the right version, then copy the result to the output.

     <br><dt>`<samp><span class="samp">l</span></samp>'<dd>Copy the left version to the output.

     <br><dt>`<samp><span class="samp">q</span></samp>'<dd>Quit.

     <br><dt>`<samp><span class="samp">r</span></samp>'<dd>Copy the right version to the output.

     <br><dt>`<samp><span class="samp">s</span></samp>'<dd>Silently copy common lines.

     <br><dt>`<samp><span class="samp">v</span></samp>'<dd>Verbosely copy common lines.  This is the default. 
</dl>

   <p><a name="index-EDITOR-79"></a>The text editor invoked is specified by the <samp><span class="env">EDITOR</span></samp> environment
variable if it is set.  The default is system-dependent.

<div class="node">
<p><hr>
<a name="Merging-with-patch"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Making-Patches">Making Patches</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Interactive-Merging">Interactive Merging</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Top">Top</a>

</div>

<h2 class="chapter">10 Merging with <samp><span class="command">patch</span></samp></h2>

<p><samp><span class="command">patch</span></samp> takes comparison output produced by <samp><span class="command">diff</span></samp> and applies
the differences to a copy of the original file, producing a patched
version.  With <samp><span class="command">patch</span></samp>, you can distribute just the changes to a
set of files instead of distributing the entire file set; your
correspondents can apply <samp><span class="command">patch</span></samp> to update their copy of the files
with your changes.  <samp><span class="command">patch</span></samp> automatically determines the diff
format, skips any leading or trailing headers, and uses the headers to
determine which file to patch.  This lets your correspondents feed a
mail message containing a difference listing directly to
<samp><span class="command">patch</span></samp>.

   <p><samp><span class="command">patch</span></samp> detects and warns about common problems like forward
patches.  It saves any patches that it could not apply.  It can also maintain a
<code>patchlevel.h</code> file to ensure that your correspondents apply
diffs in the proper order.

   <p><samp><span class="command">patch</span></samp> accepts a series of diffs in its standard input, usually
separated by headers that specify which file to patch.  It applies
<samp><span class="command">diff</span></samp> hunks (see <a href="#Hunks">Hunks</a>) one by one.  If a hunk does not
exactly match the original file, <samp><span class="command">patch</span></samp> uses heuristics to try to
patch the file as well as it can.  If no approximate match can be found,
<samp><span class="command">patch</span></samp> rejects the hunk and skips to the next hunk.  <samp><span class="command">patch</span></samp>
normally replaces each file <var>f</var> with its new version, putting reject
hunks (if any) into `<samp><var>f</var><span class="samp">.rej</span></samp>'.

   <p>See <a href="#Invoking-patch">Invoking patch</a>, for detailed information on the options to
<samp><span class="command">patch</span></samp>.

<ul class="menu">
<li><a accesskey="1" href="#patch-Input">patch Input</a>:             Selecting the type of <samp><span class="command">patch</span></samp> input. 
<li><a accesskey="2" href="#Revision-Control">Revision Control</a>:        Getting files from <span class="sc">rcs</span>, <span class="sc">sccs</span>, etc. 
<li><a accesskey="3" href="#Imperfect">Imperfect</a>:               Dealing with imperfect patches. 
<li><a accesskey="4" href="#Creating-and-Removing">Creating and Removing</a>:   Creating and removing files with a patch. 
<li><a accesskey="5" href="#Patching-Time-Stamps">Patching Time Stamps</a>:    Updating time stamps on patched files. 
<li><a accesskey="6" href="#Multiple-Patches">Multiple Patches</a>:        Handling multiple patches in a file. 
<li><a accesskey="7" href="#patch-Directories">patch Directories</a>:       Changing directory and stripping directories. 
<li><a accesskey="8" href="#Backups">Backups</a>:                 Whether backup files are made. 
<li><a accesskey="9" href="#Backup-Names">Backup Names</a>:            Backup file names. 
<li><a href="#Reject-Names">Reject Names</a>:            Reject file names. 
<li><a href="#patch-Messages">patch Messages</a>:          Messages and questions <samp><span class="command">patch</span></samp> can produce. 
<li><a href="#patch-and-POSIX">patch and POSIX</a>:         Conformance to the <span class="sc">posix</span> standard. 
<li><a href="#patch-and-Tradition">patch and Tradition</a>:     <span class="sc">gnu</span> versus traditional <samp><span class="command">patch</span></samp>. 
</ul>

<div class="node">
<p><hr>
<a name="patch-Input"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Revision-Control">Revision Control</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Merging-with-patch">Merging with patch</a>

</div>

<h3 class="section">10.1 Selecting the <samp><span class="command">patch</span></samp> Input Format</h3>

<p><a name="index-g_t_0040command_007bpatch_007d-input-format-80"></a>
<samp><span class="command">patch</span></samp> normally determines which <samp><span class="command">diff</span></samp> format the patch
file uses by examining its contents.  For patch files that contain
particularly confusing leading text, you might need to use one of the
following options to force <samp><span class="command">patch</span></samp> to interpret the patch file as a
certain format of diff.  The output formats listed here are the only
ones that <samp><span class="command">patch</span></samp> can understand.

     <dl>
<dt><samp><span class="option">-c</span></samp><dt><samp><span class="option">--context</span></samp><dd>context diff.

     <br><dt><samp><span class="option">-e</span></samp><dt><samp><span class="option">--ed</span></samp><dd><samp><span class="command">ed</span></samp> script.

     <br><dt><samp><span class="option">-n</span></samp><dt><samp><span class="option">--normal</span></samp><dd>normal diff.

     <br><dt><samp><span class="option">-u</span></samp><dt><samp><span class="option">--unified</span></samp><dd>unified diff. 
</dl>

<div class="node">
<p><hr>
<a name="Revision-Control"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Imperfect">Imperfect</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#patch-Input">patch Input</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Merging-with-patch">Merging with patch</a>

</div>

<h3 class="section">10.2 Revision Control</h3>

<p><a name="index-revision-control-81"></a><a name="index-version-control-82"></a><a name="index-g_t_0040sc_007brcs_007d-83"></a><a name="index-ClearCase-84"></a><a name="index-g_t_0040sc_007bsccs_007d-85"></a>
If a nonexistent input file is under a revision control system
supported by <samp><span class="command">patch</span></samp>, <samp><span class="command">patch</span></samp> normally asks the user
whether to get (or check out) the file from the revision control
system.  Patch currently supports <span class="sc">rcs</span>, ClearCase and <span class="sc">sccs</span>. 
Under <span class="sc">rcs</span> and <span class="sc">sccs</span>, <samp><span class="command">patch</span></samp> also asks when the input
file is read-only and matches the default version in the revision
control system.

   <p><a name="index-PATCH_005fGET-86"></a>The <samp><span class="option">-g </span><var>num</var></samp> or <samp><span class="option">--get=</span><var>num</var></samp> affects access
to files under supported revision control systems.  If <var>num</var> is
positive, <samp><span class="command">patch</span></samp> gets the file without asking the user; if
zero, <samp><span class="command">patch</span></samp> neither asks the user nor gets the file; and if
negative, <samp><span class="command">patch</span></samp> asks the user before getting the file.  The
default value of <var>num</var> is given by the value of the
<samp><span class="env">PATCH_GET</span></samp> environment variable if it is set; if not, the default
value is zero if <samp><span class="command">patch</span></samp> is conforming to <span class="sc">posix</span>, negative
otherwise.  See <a href="#patch-and-POSIX">patch and POSIX</a>.

   <p><a name="index-VERSION_005fCONTROL-87"></a>The choice of revision control system is unaffected by the
<samp><span class="env">VERSION_CONTROL</span></samp> environment variable (see <a href="#Backup-Names">Backup Names</a>).

<div class="node">
<p><hr>
<a name="Imperfect"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Creating-and-Removing">Creating and Removing</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Revision-Control">Revision Control</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Merging-with-patch">Merging with patch</a>

</div>

<h3 class="section">10.3 Applying Imperfect Patches</h3>

<p><a name="index-imperfect-patch-application-88"></a>
<samp><span class="command">patch</span></samp> tries to skip any leading text in the patch file,
apply the diff, and then skip any trailing text.  Thus you can feed a
mail message directly to <samp><span class="command">patch</span></samp>, and it should work.  If the
entire diff is indented by a constant amount of white space,
<samp><span class="command">patch</span></samp> automatically ignores the indentation.  If a context
diff contains trailing carriage return on each line, <samp><span class="command">patch</span></samp>
automatically ignores the carriage return.  If a context diff has been
encapsulated by prepending `<samp><span class="samp">-&nbsp;</span></samp>'<!-- /@w --> to lines beginning with `<samp><span class="samp">-</span></samp>'
as per <a href="ftp://ftp.isi.edu/in-notes/rfc934.txt">Internet RFC 934</a>,
<samp><span class="command">patch</span></samp> automatically unencapsulates the input.

   <p>However, certain other types of imperfect input require user
intervention or testing.

<ul class="menu">
<li><a accesskey="1" href="#Changed-White-Space">Changed White Space</a>:  When tabs and spaces don't match exactly. 
<li><a accesskey="2" href="#Reversed-Patches">Reversed Patches</a>:     Applying reversed patches correctly. 
<li><a accesskey="3" href="#Inexact">Inexact</a>:              Helping <samp><span class="command">patch</span></samp> find close matches. 
<li><a accesskey="4" href="#Dry-Runs">Dry Runs</a>:             Predicting what <samp><span class="command">patch</span></samp> will do. 
</ul>

<div class="node">
<p><hr>
<a name="Changed-White-Space"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Reversed-Patches">Reversed Patches</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Imperfect">Imperfect</a>

</div>

<h4 class="subsection">10.3.1 Applying Patches with Changed White Space</h4>

<p><a name="index-white-space-in-patches-89"></a>
Sometimes mailers, editors, or other programs change spaces into tabs,
or vice versa.  If this happens to a patch file or an input file, the
files might look the same, but <samp><span class="command">patch</span></samp> will not be able to match
them properly.  If this problem occurs, use the <samp><span class="option">-l</span></samp> or
<samp><span class="option">--ignore-white-space</span></samp> option, which makes <samp><span class="command">patch</span></samp> compare
blank characters (i.e. spaces and tabs) loosely so that any nonempty
sequence of blanks in the patch file matches any nonempty sequence of
blanks in the input files.  Non-blank
characters must still match exactly.  Each line of the context must
still match a line in the input file.

<div class="node">
<p><hr>
<a name="Reversed-Patches"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Inexact">Inexact</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Changed-White-Space">Changed White Space</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Imperfect">Imperfect</a>

</div>

<h4 class="subsection">10.3.2 Applying Reversed Patches</h4>

<p><a name="index-reversed-patches-90"></a>
Sometimes people run <samp><span class="command">diff</span></samp> with the new file first instead of
second.  This creates a diff that is &ldquo;reversed&rdquo;.  To apply such
patches, give <samp><span class="command">patch</span></samp> the <samp><span class="option">-R</span></samp> or <samp><span class="option">--reverse</span></samp> option. 
<samp><span class="command">patch</span></samp> then attempts to swap each hunk around before applying it. 
Rejects come out in the swapped format.

   <p>Often <samp><span class="command">patch</span></samp> can guess that the patch is reversed.  If the first
hunk of a patch fails, <samp><span class="command">patch</span></samp> reverses the hunk to see if it can
apply it that way.  If it can, <samp><span class="command">patch</span></samp> asks you if you want to have
the <samp><span class="option">-R</span></samp> option set; if it can't, <samp><span class="command">patch</span></samp> continues to apply
the patch normally.  This method cannot detect a reversed patch if it is
a normal diff and the first command is an append (which should have been
a delete) since appends always succeed, because a null context matches
anywhere.  But most patches add or change lines rather than delete them,
so most reversed normal diffs begin with a delete, which fails, and
<samp><span class="command">patch</span></samp> notices.

   <p>If you apply a patch that you have already applied, <samp><span class="command">patch</span></samp> thinks
it is a reversed patch and offers to un-apply the patch.  This could be
construed as a feature.  If you did this inadvertently and you don't
want to un-apply the patch, just answer `<samp><span class="samp">n</span></samp>' to this offer and to
the subsequent &ldquo;apply anyway&rdquo; question&mdash;or type <kbd>C-c</kbd> to kill the
<samp><span class="command">patch</span></samp> process.

<div class="node">
<p><hr>
<a name="Inexact"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Dry-Runs">Dry Runs</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Reversed-Patches">Reversed Patches</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Imperfect">Imperfect</a>

</div>

<h4 class="subsection">10.3.3 Helping <samp><span class="command">patch</span></samp> Find Inexact Matches</h4>

<p><a name="index-inexact-patches-91"></a><a name="index-fuzz-factor-when-patching-92"></a>
For context diffs, and to a lesser extent normal diffs, <samp><span class="command">patch</span></samp> can
detect when the line numbers mentioned in the patch are incorrect, and
it attempts to find the correct place to apply each hunk of the patch. 
As a first guess, it takes the line number mentioned in the hunk, plus
or minus any offset used in applying the previous hunk.  If that is not
the correct place, <samp><span class="command">patch</span></samp> scans both forward and backward for a
set of lines matching the context given in the hunk.

   <p>First <samp><span class="command">patch</span></samp> looks for a place where all lines of the context
match.  If it cannot find such a place, and it is reading a context or
unified diff, and the maximum fuzz factor is set to 1 or more, then
<samp><span class="command">patch</span></samp> makes another scan, ignoring the first and last line of
context.  If that fails, and the maximum fuzz factor is set to 2 or
more, it makes another scan, ignoring the first two and last two lines
of context are ignored.  It continues similarly if the maximum fuzz
factor is larger.

   <p>The <samp><span class="option">-F </span><var>lines</var></samp> or <samp><span class="option">--fuzz=</span><var>lines</var></samp> option sets the
maximum fuzz factor to <var>lines</var>.  This option only applies to context
and unified diffs; it ignores up to <var>lines</var> lines while looking for
the place to install a hunk.  Note that a larger fuzz factor increases
the odds of making a faulty patch.  The default fuzz factor is 2; there
is no point to setting it to more than the number of lines of context
in the diff, ordinarily 3.

   <p>If <samp><span class="command">patch</span></samp> cannot find a place to install a hunk of the patch, it
writes the hunk out to a reject file (see <a href="#Reject-Names">Reject Names</a>, for information
on how reject files are named).  It writes out rejected hunks in context
format no matter what form the input patch is in.  If the input is a
normal or <samp><span class="command">ed</span></samp> diff, many of the contexts are simply null.  The
line numbers on the hunks in the reject file may be different from those
in the patch file: they show the approximate location where <samp><span class="command">patch</span></samp>
thinks the failed hunks belong in the new file rather than in the old
one.

   <p>If the <samp><span class="option">--verbose</span></samp> option is given, then
as it completes each hunk <samp><span class="command">patch</span></samp> tells you whether the hunk
succeeded or failed, and if it failed, on which line (in the new file)
<samp><span class="command">patch</span></samp> thinks the hunk should go.  If this is different from the
line number specified in the diff, it tells you the offset.  A single
large offset <em>may</em> indicate that <samp><span class="command">patch</span></samp> installed a hunk in
the wrong place.  <samp><span class="command">patch</span></samp> also tells you if it used a fuzz factor
to make the match, in which case you should also be slightly suspicious.

   <p><samp><span class="command">patch</span></samp> cannot tell if the line numbers are off in an <samp><span class="command">ed</span></samp>
script, and can only detect wrong line numbers in a normal diff when it
finds a change or delete command.  It may have the same problem with a
context diff using a fuzz factor equal to or greater than the number of
lines of context shown in the diff (typically 3).  In these cases, you
should probably look at a context diff between your original and patched
input files to see if the changes make sense.  Compiling without errors
is a pretty good indication that the patch worked, but not a guarantee.

   <p>A patch against an empty file applies to a nonexistent file, and vice
versa.  See <a href="#Creating-and-Removing">Creating and Removing</a>.

   <p><samp><span class="command">patch</span></samp> usually produces the correct results, even when it must
make many guesses.  However, the results are guaranteed only when
the patch is applied to an exact copy of the file that the patch was
generated from.

<div class="node">
<p><hr>
<a name="Dry-Runs"></a>
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Inexact">Inexact</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Imperfect">Imperfect</a>

</div>

<h4 class="subsection">10.3.4 Predicting what <samp><span class="command">patch</span></samp> will do</h4>

<p><a name="index-testing-_0040command_007bpatch_007d-93"></a><a name="index-dry-runs-for-_0040command_007bpatch_007d-94"></a>
It may not be obvious in advance what <samp><span class="command">patch</span></samp> will do with a
complicated or poorly formatted patch.  If you are concerned that the
input might cause <samp><span class="command">patch</span></samp> to modify the wrong files, you can
use the <samp><span class="option">--dry-run</span></samp> option, which causes <samp><span class="command">patch</span></samp> to
print the results of applying patches without actually changing any
files.  You can then inspect the diagnostics generated by the dry run
to see whether <samp><span class="command">patch</span></samp> will modify the files that you expect. 
If the patch does not do what you want, you can modify the patch (or
the other options to <samp><span class="command">patch</span></samp>) and try another dry run.  Once
you are satisfied with the proposed patch you can apply it by invoking
<samp><span class="command">patch</span></samp> as before, but this time without the
<samp><span class="option">--dry-run</span></samp> option.

<div class="node">
<p><hr>
<a name="Creating-and-Removing"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Patching-Time-Stamps">Patching Time Stamps</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Imperfect">Imperfect</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Merging-with-patch">Merging with patch</a>

</div>

<h3 class="section">10.4 Creating and Removing Files</h3>

<p><a name="index-creating-files-95"></a><a name="index-empty-files_002c-removing-96"></a><a name="index-removing-empty-files-97"></a>
Sometimes when comparing two directories, a file may exist in one
directory but not the other.  If you give <samp><span class="command">diff</span></samp> the
<samp><span class="option">-N</span></samp> or <samp><span class="option">--new-file</span></samp> option, or if you supply an old or
new file that is named <samp><span class="file">/dev/null</span></samp> or is empty and is dated the
Epoch (1970-01-01 00:00:00 UTC), <samp><span class="command">diff</span></samp> outputs a patch that
adds or deletes the contents of this file.  When given such a patch,
<samp><span class="command">patch</span></samp> normally creates a new file or removes the old file. 
However, when conforming to <span class="sc">posix</span> (see <a href="#patch-and-POSIX">patch and POSIX</a>),
<samp><span class="command">patch</span></samp> does not remove the old file, but leaves it empty. 
The <samp><span class="option">-E</span></samp> or <samp><span class="option">--remove-empty-files</span></samp> option causes
<samp><span class="command">patch</span></samp> to remove output files that are empty after applying a
patch, even if the patch does not appear to be one that removed the
file.

   <p>If the patch appears to create a file that already exists,
<samp><span class="command">patch</span></samp> asks for confirmation before applying the patch.

<div class="node">
<p><hr>
<a name="Patching-Time-Stamps"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Multiple-Patches">Multiple Patches</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Creating-and-Removing">Creating and Removing</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Merging-with-patch">Merging with patch</a>

</div>

<h3 class="section">10.5 Updating Time Stamps on Patched Files</h3>

<p><a name="index-time-stamps-on-patched-files-98"></a>
When <samp><span class="command">patch</span></samp> updates a file, it normally sets the file's
last-modified time stamp to the current time of day.  If you are using
<samp><span class="command">patch</span></samp> to track a software distribution, this can cause
<samp><span class="command">make</span></samp> to incorrectly conclude that a patched file is out of
date.  For example, if <samp><span class="file">syntax.c</span></samp> depends on <samp><span class="file">syntax.y</span></samp>, and
<samp><span class="command">patch</span></samp> updates <samp><span class="file">syntax.c</span></samp> and then <samp><span class="file">syntax.y</span></samp>, then
<samp><span class="file">syntax.c</span></samp> will normally appear to be out of date with respect to
<samp><span class="file">syntax.y</span></samp> even though its contents are actually up to date.

   <p>The <samp><span class="option">-Z</span></samp> or <samp><span class="option">--set-utc</span></samp> option causes <samp><span class="command">patch</span></samp> to
set a patched file's modification and access times to the time stamps
given in context diff headers.  If the context diff headers do not
specify a time zone, they are assumed to use Coordinated Universal
Time (<span class="sc">utc</span>, often known as <span class="sc">gmt</span>).

   <p>The <samp><span class="option">-T</span></samp> or <samp><span class="option">--set-time</span></samp> option acts like <samp><span class="option">-Z</span></samp> or
<samp><span class="option">--set-utc</span></samp>, except that it assumes that the context diff
headers' time stamps use local time instead of <span class="sc">utc</span>.  This option
is not recommended, because patches using local time cannot easily be
used by people in other time zones, and because local time stamps are
ambiguous when local clocks move backwards during daylight-saving time
adjustments.  If the context diff headers specify a time zone, this
option is equivalent to <samp><span class="option">-Z</span></samp> or <samp><span class="option">--set-utc</span></samp>.

   <p><samp><span class="command">patch</span></samp> normally refrains from setting a file's time stamps if
the file's original last-modified time stamp does not match the time
given in the diff header, of if the file's contents do not exactly
match the patch.  However, if the <samp><span class="option">-f</span></samp> or <samp><span class="option">--force</span></samp>
option is given, the file's time stamps are set regardless.

   <p>Due to the limitations of the current <samp><span class="command">diff</span></samp> format,
<samp><span class="command">patch</span></samp> cannot update the times of files whose contents have
not changed.  Also, if you set file time stamps to values other than
the current time of day, you should also remove (e.g., with `<samp><span class="samp">make
clean</span></samp>') all files that depend on the patched files, so that later
invocations of <samp><span class="command">make</span></samp> do not get confused by the patched
files' times.

<div class="node">
<p><hr>
<a name="Multiple-Patches"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#patch-Directories">patch Directories</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Patching-Time-Stamps">Patching Time Stamps</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Merging-with-patch">Merging with patch</a>

</div>

<h3 class="section">10.6 Multiple Patches in a File</h3>

<p><a name="index-multiple-patches-99"></a><a name="index-intuiting-file-names-from-patches-100"></a>
If the patch file contains more than one patch, and if you do not
specify an input file on the command line, <samp><span class="command">patch</span></samp> tries to
apply each patch as if they came from separate patch files.  This
means that it determines the name of the file to patch for each patch,
and that it examines the leading text before each patch for file names
and prerequisite revision level (see <a href="#Making-Patches">Making Patches</a>, for more on
that topic).

   <p><samp><span class="command">patch</span></samp> uses the following rules to intuit a file name from
the leading text before a patch.  First, <samp><span class="command">patch</span></samp> takes an
ordered list of candidate file names as follows:

     <ul>
<li>If the header is that of a context diff, <samp><span class="command">patch</span></samp> takes the old
and new file names in the header.  A name is ignored if it does not
have enough slashes to satisfy the <samp><span class="option">-p</span><var>num</var></samp> or
<samp><span class="option">--strip=</span><var>num</var></samp> option.  The name <samp><span class="file">/dev/null</span></samp> is also
ignored.

     <li>If there is an `<samp><span class="samp">Index:</span></samp>' line in the leading garbage and if either
the old and new names are both absent or if <samp><span class="command">patch</span></samp> is
conforming to <span class="sc">posix</span>, <samp><span class="command">patch</span></samp> takes the name in the
`<samp><span class="samp">Index:</span></samp>' line.

     <li>For the purpose of the following rules, the candidate file names are
considered to be in the order (old, new, index), regardless of the
order that they appear in the header. 
</ul>

<p class="noindent">Then <samp><span class="command">patch</span></samp> selects a file name from the candidate list as
follows:

     <ul>
<li>If some of the named files exist, <samp><span class="command">patch</span></samp> selects the first
name if conforming to <span class="sc">posix</span>, and the best name otherwise.

     <li>If <samp><span class="command">patch</span></samp> is not ignoring <span class="sc">rcs</span>, ClearCase, and <span class="sc">sccs</span>
(see <a href="#Revision-Control">Revision Control</a>), and no named files exist but an <span class="sc">rcs</span>,
ClearCase, or <span class="sc">sccs</span> master is found, <samp><span class="command">patch</span></samp> selects the
first named file with an <span class="sc">rcs</span>, ClearCase, or <span class="sc">sccs</span> master.

     <li>If no named files exist, no <span class="sc">rcs</span>, ClearCase, or <span class="sc">sccs</span> master
was found, some names are given, <samp><span class="command">patch</span></samp> is not conforming to
<span class="sc">posix</span>, and the patch appears to create a file, <samp><span class="command">patch</span></samp>
selects the best name requiring the creation of the fewest
directories.

     <li>If no file name results from the above heuristics, you are asked for
the name of the file to patch, and <samp><span class="command">patch</span></samp> selects that name. 
</ul>

   <p>To determine the <dfn>best</dfn> of a nonempty list of file names,
<samp><span class="command">patch</span></samp> first takes all the names with the fewest path name
components; of those, it then takes all the names with the shortest
basename; of those, it then takes all the shortest names; finally, it
takes the first remaining name.

   <p>See <a href="#patch-and-POSIX">patch and POSIX</a>, to see whether <samp><span class="command">patch</span></samp> is conforming
to <span class="sc">posix</span>.

<div class="node">
<p><hr>
<a name="patch-Directories"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Backups">Backups</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Multiple-Patches">Multiple Patches</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Merging-with-patch">Merging with patch</a>

</div>

<h3 class="section">10.7 Applying Patches in Other Directories</h3>

<p><a name="index-directories-and-patch-101"></a><a name="index-patching-directories-102"></a>
The <samp><span class="option">-d </span><var>directory</var></samp> or <samp><span class="option">--directory=</span><var>directory</var></samp>
option to <samp><span class="command">patch</span></samp> makes directory <var>directory</var> the current
directory for interpreting both file names in the patch file, and file
names given as arguments to other options (such as <samp><span class="option">-B</span></samp> and
<samp><span class="option">-o</span></samp>).  For example, while in a mail reading program, you can patch
a file in the <samp><span class="file">/usr/src/emacs</span></samp> directory directly from a message
containing the patch like this:

<pre class="example">     | patch -d /usr/src/emacs
</pre>
   <p>Sometimes the file names given in a patch contain leading directories,
but you keep your files in a directory different from the one given in
the patch.  In those cases, you can use the
<samp><span class="option">-p</span><var>number</var></samp> or <samp><span class="option">--strip=</span><var>number</var></samp>
option to set the file name strip count to <var>number</var>.  The strip
count tells <samp><span class="command">patch</span></samp> how many slashes, along with the directory
names between them, to strip from the front of file names.  A sequence
of one or more adjacent slashes is counted as a single slash.  By
default, <samp><span class="command">patch</span></samp> strips off all leading directories, leaving
just the base file names.

   <p>For example, suppose the file name in the patch file is
<samp><span class="file">/gnu/src/emacs/etc/NEWS</span></samp>.  Using <samp><span class="option">-p0</span></samp> gives the
entire file name unmodified, <samp><span class="option">-p1</span></samp> gives
<samp><span class="file">gnu/src/emacs/etc/NEWS</span></samp> (no leading slash), <samp><span class="option">-p4</span></samp> gives
<samp><span class="file">etc/NEWS</span></samp>, and not specifying <samp><span class="option">-p</span></samp> at all gives <samp><span class="file">NEWS</span></samp>.

   <p><samp><span class="command">patch</span></samp> looks for each file (after any slashes have been stripped)
in the current directory, or if you used the <samp><span class="option">-d </span><var>directory</var></samp>
option, in that directory.

<div class="node">
<p><hr>
<a name="Backups"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Backup-Names">Backup Names</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#patch-Directories">patch Directories</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Merging-with-patch">Merging with patch</a>

</div>

<h3 class="section">10.8 Backup Files</h3>

<p><a name="index-backup-file-strategy-103"></a>
Normally, <samp><span class="command">patch</span></samp> creates a backup file if the patch does not
exactly match the original input file, because in that case the
original data might not be recovered if you undo the patch with
`<samp><span class="samp">patch -R</span></samp>' (see <a href="#Reversed-Patches">Reversed Patches</a>).  However, when conforming
to <span class="sc">posix</span>, <samp><span class="command">patch</span></samp> does not create backup files by
default.  See <a href="#patch-and-POSIX">patch and POSIX</a>.

   <p>The <samp><span class="option">-b</span></samp> or <samp><span class="option">--backup</span></samp> option causes <samp><span class="command">patch</span></samp> to
make a backup file regardless of whether the patch matches the
original input.  The <samp><span class="option">--backup-if-mismatch</span></samp> option causes
<samp><span class="command">patch</span></samp> to create backup files for mismatches files; this is
the default when not conforming to <span class="sc">posix</span>.  The
<samp><span class="option">--no-backup-if-mismatch</span></samp> option causes <samp><span class="command">patch</span></samp> to not
create backup files, even for mismatched patches; this is the default
when conforming to <span class="sc">posix</span>.

   <p>When backing up a file that does not exist, an empty, unreadable
backup file is created as a placeholder to represent the nonexistent
file.

<div class="node">
<p><hr>
<a name="Backup-Names"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Reject-Names">Reject Names</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Backups">Backups</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Merging-with-patch">Merging with patch</a>

</div>

<h3 class="section">10.9 Backup File Names</h3>

<p><a name="index-backup-file-names-104"></a>
Normally, <samp><span class="command">patch</span></samp> renames an original input file into a backup
file by appending to its name the extension `<samp><span class="samp">.orig</span></samp>', or `<samp><span class="samp">~</span></samp>'
if using `<samp><span class="samp">.orig</span></samp>' would make the backup file name too
long.<a rel="footnote" href="#fn-1" name="fnd-1"><sup>1</sup></a>  The <samp><span class="option">-z </span><var>backup-suffix</var></samp> or
<samp><span class="option">--suffix=</span><var>backup-suffix</var></samp> option causes <samp><span class="command">patch</span></samp> to
use <var>backup-suffix</var> as the backup extension instead.

   <p><a name="index-SIMPLE_005fBACKUP_005fSUFFIX-105"></a>Alternately, you can specify the extension for backup files with the
<samp><span class="env">SIMPLE_BACKUP_SUFFIX</span></samp> environment variable, which the options
override.

   <p><samp><span class="command">patch</span></samp> can also create numbered backup files the way <span class="sc">gnu</span> Emacs
does.  With this method, instead of having a single backup of each file,
<samp><span class="command">patch</span></samp> makes a new backup file name each time it patches a file. 
For example, the backups of a file named <samp><span class="file">sink</span></samp> would be called,
successively, <samp><span class="file">sink.~1~</span></samp>, <samp><span class="file">sink.~2~</span></samp>, <samp><span class="file">sink.~3~</span></samp>, etc.

   <p><a name="index-PATCH_005fVERSION_005fCONTROL-106"></a><a name="index-VERSION_005fCONTROL-107"></a>The <samp><span class="option">-V </span><var>backup-style</var></samp> or
<samp><span class="option">--version-control=</span><var>backup-style</var></samp> option takes as an
argument a method for creating backup file names.  You can alternately
control the type of backups that <samp><span class="command">patch</span></samp> makes with the
<samp><span class="env">PATCH_VERSION_CONTROL</span></samp> environment variable, which the
<samp><span class="option">-V</span></samp> option overrides.  If <samp><span class="env">PATCH_VERSION_CONTROL</span></samp> is not
set, the <samp><span class="env">VERSION_CONTROL</span></samp> environment variable is used instead. 
Please note that these options and variables control backup file
names; they do not affect the choice of revision control system
(see <a href="#Revision-Control">Revision Control</a>).

   <p>The values of these environment variables and the argument to the
<samp><span class="option">-V</span></samp> option are like the <span class="sc">gnu</span> Emacs <code>version-control</code>
variable (see <a href="emacs.html#Backup-Names">Backup Names</a>,
for more information on backup versions in Emacs).  They also
recognize synonyms that are more descriptive.  The valid values are
listed below; unique abbreviations are acceptable.

     <dl>
<dt><samp><span class="option">t</span></samp><dt><samp><span class="option">numbered</span></samp><dd>Always make numbered backups.

     <br><dt><samp><span class="option">nil</span></samp><dt><samp><span class="option">existing</span></samp><dd>Make numbered backups of files that already have them, simple backups of
the others.  This is the default.

     <br><dt><samp><span class="option">never</span></samp><dt><samp><span class="option">simple</span></samp><dd>Always make simple backups. 
</dl>

   <p>You can also tell <samp><span class="command">patch</span></samp> to prepend a prefix, such as a
directory name, to produce backup file names.  The <samp><span class="option">-B
</span><var>prefix</var></samp> or <samp><span class="option">--prefix=</span><var>prefix</var></samp> option makes backup
files by prepending <var>prefix</var> to them.  The <samp><span class="option">-Y
</span><var>prefix</var></samp> or <samp><span class="option">--basename-prefix=</span><var>prefix</var></samp> prepends
<var>prefix</var> to the last file name component of backup file names
instead; for example, <samp><span class="option">-Y ~</span></samp> causes the backup name for
<samp><span class="file">dir/file.c</span></samp> to be <samp><span class="file">dir/~file.c</span></samp>.  If you use either of
these prefix options, the suffix-based options are ignored.

   <p>If you specify the output file with the <samp><span class="option">-o</span></samp> option, that file is
the one that is backed up, not the input file.

   <p>Options that affect the names of backup files do not affect whether
backups are made.  For example, if you specify the
<samp><span class="option">--no-backup-if-mismatch</span></samp> option, none of the options described
in this section have any affect, because no backups are made.

<div class="node">
<p><hr>
<a name="Reject-Names"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#patch-Messages">patch Messages</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Backup-Names">Backup Names</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Merging-with-patch">Merging with patch</a>

</div>

<h3 class="section">10.10 Reject File Names</h3>

<p><a name="index-reject-file-names-108"></a>
The names for reject files (files containing patches that
<samp><span class="command">patch</span></samp> could not find a place to apply) are normally the name
of the output file with `<samp><span class="samp">.rej</span></samp>' appended (or `<samp><span class="samp">#</span></samp>' if if using
`<samp><span class="samp">.rej</span></samp>' would make the backup file name too long).

   <p>Alternatively, you can tell <samp><span class="command">patch</span></samp> to place all of the rejected
patches in a single file.  The <samp><span class="option">-r </span><var>reject-file</var></samp> or
<samp><span class="option">--reject-file=</span><var>reject-file</var></samp> option uses <var>reject-file</var> as
the reject file name.

<div class="node">
<p><hr>
<a name="patch-Messages"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#patch-and-POSIX">patch and POSIX</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Reject-Names">Reject Names</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Merging-with-patch">Merging with patch</a>

</div>

<h3 class="section">10.11 Messages and Questions from <samp><span class="command">patch</span></samp></h3>

<p><a name="index-g_t_0040command_007bpatch_007d-messages-and-questions-109"></a><a name="index-diagnostics-from-_0040command_007bpatch_007d-110"></a><a name="index-messages-from-_0040command_007bpatch_007d-111"></a>
<samp><span class="command">patch</span></samp> can produce a variety of messages, especially if it
has trouble decoding its input.  In a few situations where it's not
sure how to proceed, <samp><span class="command">patch</span></samp> normally prompts you for more
information from the keyboard.  There are options to produce more or
fewer messages, to have it not ask for keyboard input, and to
affect the way that file names are quoted in messages.

<ul class="menu">
<li><a accesskey="1" href="#More-or-Fewer-Messages">More or Fewer Messages</a>:     Controlling the verbosity of <samp><span class="command">patch</span></samp>. 
<li><a accesskey="2" href="#patch-and-Keyboard-Input">patch and Keyboard Input</a>:   Inhibiting keyboard input. 
<li><a accesskey="3" href="#patch-Quoting-Style">patch Quoting Style</a>:        Quoting file names in diagnostics. 
</ul>

   <p><samp><span class="command">patch</span></samp> exits with status 0 if all hunks are applied successfully,
1 if some hunks cannot be applied, and 2 if there is more serious trouble. 
When applying a set of patches in a loop, you should check the
exit status, so you don't apply a later patch to a partially patched
file.

<div class="node">
<p><hr>
<a name="More-or-Fewer-Messages"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#patch-and-Keyboard-Input">patch and Keyboard Input</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#patch-Messages">patch Messages</a>

</div>

<h4 class="subsection">10.11.1 Controlling the Verbosity of <samp><span class="command">patch</span></samp></h4>

<p><a name="index-verbose-messages-from-_0040command_007bpatch_007d-112"></a><a name="index-inhibit-messages-from-_0040command_007bpatch_007d-113"></a>
You can cause <samp><span class="command">patch</span></samp> to produce more messages by using the
<samp><span class="option">--verbose</span></samp> option.  For example, when you give this option,
the message `<samp><span class="samp">Hmm...</span></samp>' indicates that <samp><span class="command">patch</span></samp> is reading text in
the patch file, attempting to determine whether there is a patch in that
text, and if so, what kind of patch it is.

   <p>You can inhibit all terminal output from <samp><span class="command">patch</span></samp>, unless an error
occurs, by using the <samp><span class="option">-s</span></samp>, <samp><span class="option">--quiet</span></samp>, or <samp><span class="option">--silent</span></samp>
option.

<div class="node">
<p><hr>
<a name="patch-and-Keyboard-Input"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#patch-Quoting-Style">patch Quoting Style</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#More-or-Fewer-Messages">More or Fewer Messages</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#patch-Messages">patch Messages</a>

</div>

<h4 class="subsection">10.11.2 Inhibiting Keyboard Input</h4>

<p><a name="index-keyboard-input-to-_0040command_007bpatch_007d-114"></a>
There are two ways you can prevent <samp><span class="command">patch</span></samp> from asking you any
questions.  The <samp><span class="option">-f</span></samp> or <samp><span class="option">--force</span></samp> option assumes that you know
what you are doing.  It causes <samp><span class="command">patch</span></samp> to do the following:

     <ul>
<li>Skip patches that do not contain file names in their headers.

     <li>Patch files even though they have the wrong version for the
`<samp><span class="samp">Prereq:</span></samp>' line in the patch;

     <li>Assume that patches are not reversed even if they look like they are. 
</ul>

<p class="noindent">The <samp><span class="option">-t</span></samp> or <samp><span class="option">--batch</span></samp> option is similar to <samp><span class="option">-f</span></samp>, in that
it suppresses questions, but it makes somewhat different assumptions:

     <ul>
<li>Skip patches that do not contain file names in their headers
(the same as <samp><span class="option">-f</span></samp>).

     <li>Skip patches for which the file has the wrong version for the
`<samp><span class="samp">Prereq:</span></samp>' line in the patch;

     <li>Assume that patches are reversed if they look like they are. 
</ul>

<div class="node">
<p><hr>
<a name="patch-Quoting-Style"></a>
Previous:&nbsp;<a rel="previous" accesskey="p" href="#patch-and-Keyboard-Input">patch and Keyboard Input</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#patch-Messages">patch Messages</a>

</div>

<h4 class="subsection">10.11.3 <samp><span class="command">patch</span></samp> Quoting Style</h4>

<p><a name="index-quoting-style-115"></a>
When <samp><span class="command">patch</span></samp> outputs a file name in a diagnostic message, it
can format the name in any of several ways.  This can be useful to
output file names unambiguously, even if they contain punctuation or
special characters like newlines.  The
<samp><span class="option">--quoting-style=</span><var>word</var></samp> option controls how names are
output.  The <var>word</var> should be one of the following:

     <dl>
<dt>`<samp><span class="samp">literal</span></samp>'<dd>Output names as-is. 
<br><dt>`<samp><span class="samp">shell</span></samp>'<dd>Quote names for the shell if they contain shell metacharacters or would
cause ambiguous output. 
<br><dt>`<samp><span class="samp">shell-always</span></samp>'<dd>Quote names for the shell, even if they would normally not require quoting. 
<br><dt>`<samp><span class="samp">c</span></samp>'<dd>Quote names as for a C language string. 
<br><dt>`<samp><span class="samp">escape</span></samp>'<dd>Quote as with `<samp><span class="samp">c</span></samp>' except omit the surrounding double-quote
characters. 
<!-- The following are not yet implemented in patch 2.5.4. -->
<!-- @item clocale -->
<!-- Quote as with @samp{c} except use quotation marks appropriate for the -->
<!-- locale. -->
<!-- @item locale -->
<!-- @c Use @t instead of @samp to avoid duplicate quoting in some output styles. -->
<!-- Like @samp{clocale}, but quote @t{`like this'} instead of @t{"like -->
<!-- this"} in the default C locale.  This looks nicer on many displays. -->
</dl>

   <p><a name="index-QUOTING_005fSTYLE-116"></a>You can specify the default value of the <samp><span class="option">--quoting-style</span></samp>
option with the environment variable <samp><span class="env">QUOTING_STYLE</span></samp>.  If that
environment variable is not set, the default value is `<samp><span class="samp">shell</span></samp>',
but this default may change in a future version of <samp><span class="command">patch</span></samp>.

<div class="node">
<p><hr>
<a name="patch-and-POSIX"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#patch-and-Tradition">patch and Tradition</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#patch-Messages">patch Messages</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Merging-with-patch">Merging with patch</a>

</div>

<h3 class="section">10.12 <samp><span class="command">patch</span></samp> and the <span class="sc">posix</span> Standard</h3>

<p><a name="index-g_t_0040sc_007bposix_007d-117"></a>
<a name="index-POSIXLY_005fCORRECT-118"></a>If you specify the <samp><span class="option">--posix</span></samp> option, or set the
<samp><span class="env">POSIXLY_CORRECT</span></samp> environment variable, <samp><span class="command">patch</span></samp> conforms
more strictly to the <span class="sc">posix</span> standard, as follows:

     <ul>
<li>Take the first existing file from the list (old, new, index)
when intuiting file names from diff headers.  See <a href="#Multiple-Patches">Multiple Patches</a>.

     <li>Do not remove files that are removed by a diff. 
See <a href="#Creating-and-Removing">Creating and Removing</a>.

     <li>Do not ask whether to get files from <span class="sc">rcs</span>, ClearCase, or
<span class="sc">sccs</span>.  See <a href="#Revision-Control">Revision Control</a>.

     <li>Require that all options precede the files in the command line.

     <li>Do not backup files, even when there is a mismatch.  See <a href="#Backups">Backups</a>.

   </ul>

<div class="node">
<p><hr>
<a name="patch-and-Tradition"></a>
Previous:&nbsp;<a rel="previous" accesskey="p" href="#patch-and-POSIX">patch and POSIX</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Merging-with-patch">Merging with patch</a>

</div>

<h3 class="section">10.13 <span class="sc">gnu</span> <samp><span class="command">patch</span></samp> and Traditional <samp><span class="command">patch</span></samp></h3>

<p><a name="index-traditional-_0040command_007bpatch_007d-119"></a>
The current version of <span class="sc">gnu</span> <samp><span class="command">patch</span></samp> normally follows the
<span class="sc">posix</span> standard.  See <a href="#patch-and-POSIX">patch and POSIX</a>, for the few exceptions
to this general rule.

   <p>Unfortunately, <span class="sc">posix</span> redefined the behavior of <samp><span class="command">patch</span></samp> in
several important ways.  You should be aware of the following
differences if you must interoperate with traditional <samp><span class="command">patch</span></samp>,
or with <span class="sc">gnu</span> <samp><span class="command">patch</span></samp> version 2.1 and earlier.

     <ul>
<li>In traditional <samp><span class="command">patch</span></samp>, the <samp><span class="option">-p</span></samp> option's operand was
optional, and a bare <samp><span class="option">-p</span></samp> was equivalent to <samp><span class="option">-p0</span></samp>.  The
<samp><span class="option">-p</span></samp> option now requires an operand, and <samp><span class="option">-p 0</span></samp> is now
equivalent to <samp><span class="option">-p0</span></samp>.  For maximum compatibility, use options
like <samp><span class="option">-p0</span></samp> and <samp><span class="option">-p1</span></samp>.

     <p>Also, traditional <samp><span class="command">patch</span></samp> simply counted slashes when
stripping path prefixes; <samp><span class="command">patch</span></samp> now counts pathname
components.  That is, a sequence of one or more adjacent slashes now
counts as a single slash.  For maximum portability, avoid sending
patches containing <samp><span class="file">//</span></samp> in file names.

     <li>In traditional <samp><span class="command">patch</span></samp>, backups were enabled by default.  This
behavior is now enabled with the <samp><span class="option">-b</span></samp> or <samp><span class="option">--backup</span></samp>
option.

     <p>Conversely, in <span class="sc">posix</span> <samp><span class="command">patch</span></samp>, backups are never made,
even when there is a mismatch.  In <span class="sc">gnu</span> <samp><span class="command">patch</span></samp>, this
behavior is enabled with the <samp><span class="option">--no-backup-if-mismatch</span></samp> option,
or by conforming to <span class="sc">posix</span>.

     <p>The <samp><span class="option">-b </span><var>suffix</var></samp> option of traditional <samp><span class="command">patch</span></samp> is
equivalent to the `<samp><span class="samp">-b -z </span><var>suffix</var></samp>' options of <span class="sc">gnu</span>
<samp><span class="command">patch</span></samp>.

     <li>Traditional <samp><span class="command">patch</span></samp> used a complicated (and incompletely
documented) method to intuit the name of the file to be patched from
the patch header.  This method did not conform to <span class="sc">posix</span>, and had
a few gotchas.  Now <samp><span class="command">patch</span></samp> uses a different, equally
complicated (but better documented) method that is optionally
<span class="sc">posix</span>-conforming; we hope it has fewer gotchas.  The two methods
are compatible if the file names in the context diff header and the
`<samp><span class="samp">Index:</span></samp>' line are all identical after prefix-stripping.  Your
patch is normally compatible if each header's file names all contain
the same number of slashes.

     <li>When traditional <samp><span class="command">patch</span></samp> asked the user a question, it sent
the question to standard error and looked for an answer from the first
file in the following list that was a terminal: standard error,
standard output, <samp><span class="file">/dev/tty</span></samp>, and standard input.  Now
<samp><span class="command">patch</span></samp> sends questions to standard output and gets answers
from <samp><span class="file">/dev/tty</span></samp>.  Defaults for some answers have been changed so
that <samp><span class="command">patch</span></samp> never goes into an infinite loop when using
default answers.

     <li>Traditional <samp><span class="command">patch</span></samp> exited with a status value that counted
the number of bad hunks, or with status 1 if there was real trouble. 
Now <samp><span class="command">patch</span></samp> exits with status 1 if some hunks failed, or with
2 if there was real trouble.

     <li>Limit yourself to the following options when sending instructions
meant to be executed by anyone running <span class="sc">gnu</span> <samp><span class="command">patch</span></samp>,
traditional <samp><span class="command">patch</span></samp>, or a <samp><span class="command">patch</span></samp> that conforms to
<span class="sc">posix</span>.  Spaces are significant in the following list, and
operands are required.

     <pre class="example">          <samp><span class="option">-c</span></samp>
          <samp><span class="option">-d </span><var>dir</var></samp>
          <samp><span class="option">-D </span><var>define</var></samp>
          <samp><span class="option">-e</span></samp>
          <samp><span class="option">-l</span></samp>
          <samp><span class="option">-n</span></samp>
          <samp><span class="option">-N</span></samp>
          <samp><span class="option">-o </span><var>outfile</var></samp>
          <samp><span class="option">-p</span><var>num</var></samp>
          <samp><span class="option">-R</span></samp>
          <samp><span class="option">-r </span><var>rejectfile</var></samp>
     </pre>
     </ul>

<div class="node">
<p><hr>
<a name="Making-Patches"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Invoking-cmp">Invoking cmp</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Merging-with-patch">Merging with patch</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Top">Top</a>

</div>

<h2 class="chapter">11 Tips for Making and Using Patches</h2>

<p>Use some common sense when making and using patches.  For example,
when sending bug fixes to a program's maintainer, send several small
patches, one per independent subject, instead of one large,
harder-to-digest patch that covers all the subjects.

   <p>Here are some other things you should keep in mind if you are going to
distribute patches for updating a software package.

<ul class="menu">
<li><a accesskey="1" href="#Tips-for-Patch-Producers">Tips for Patch Producers</a>:     Advice for making patches. 
<li><a accesskey="2" href="#Tips-for-Patch-Consumers">Tips for Patch Consumers</a>:     Advice for using patches. 
<li><a accesskey="3" href="#Avoiding-Common-Mistakes">Avoiding Common Mistakes</a>:     Avoiding common mistakes when using <samp><span class="command">patch</span></samp>. 
<li><a accesskey="4" href="#Generating-Smaller-Patches">Generating Smaller Patches</a>:   How to generate smaller patches. 
</ul>

<div class="node">
<p><hr>
<a name="Tips-for-Patch-Producers"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Tips-for-Patch-Consumers">Tips for Patch Consumers</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Making-Patches">Making Patches</a>

</div>

<h3 class="section">11.1 Tips for Patch Producers</h3>

<p><a name="index-patch-producer-tips-120"></a>
To create a patch that changes an older version of a package into a
newer version, first make a copy of the older and newer versions in
adjacent subdirectories.  It is common to do that by unpacking
<samp><span class="command">tar</span></samp> archives of the two versions.

   <p>To generate the patch, use the command `<samp><span class="samp">diff -Naur </span><var>old</var>
<var>new</var></samp>' where <var>old</var> and <var>new</var> identify the old and new
directories.  The names <var>old</var> and <var>new</var> should not contain any
slashes.  The <samp><span class="option">-N</span></samp> option lets the patch create and remove
files; <samp><span class="option">-a</span></samp> lets the patch update non-text files; <samp><span class="option">-u</span></samp>
generates useful time stamps and enough context; and <samp><span class="option">-r</span></samp> lets
the patch update subdirectories.  Here is an example command, using
Bourne shell syntax:

<pre class="example">     diff -Naur gcc-3.0.3 gcc-3.0.4
</pre>
   <p>Tell your recipients how to apply the patches.  This should include
which working directory to use, and which <samp><span class="command">patch</span></samp> options to
use; the option `<samp><span class="samp">-p1</span></samp>' is recommended.  Test your procedure by
pretending to be a recipient and applying your patches to a copy of
the original files.

   <p>See <a href="#Avoiding-Common-Mistakes">Avoiding Common Mistakes</a>, for how to avoid common mistakes when
generating a patch.

<div class="node">
<p><hr>
<a name="Tips-for-Patch-Consumers"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Avoiding-Common-Mistakes">Avoiding Common Mistakes</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Tips-for-Patch-Producers">Tips for Patch Producers</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Making-Patches">Making Patches</a>

</div>

<h3 class="section">11.2 Tips for Patch Consumers</h3>

<p><a name="index-patch-consumer-tips-121"></a>
A patch producer should tell recipients how to apply the patches, so
the first rule of thumb for a patch consumer is to follow the
instructions supplied with the patch.

   <p><span class="sc">gnu</span> <samp><span class="command">diff</span></samp> can analyze files with arbitrarily long lines
and files that end in incomplete lines.  However, older versions of
<samp><span class="command">patch</span></samp> cannot patch such files.  If you are having trouble
applying such patches, try upgrading to a recent version of <span class="sc">gnu</span>
<samp><span class="command">patch</span></samp>.

<div class="node">
<p><hr>
<a name="Avoiding-Common-Mistakes"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Generating-Smaller-Patches">Generating Smaller Patches</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Tips-for-Patch-Consumers">Tips for Patch Consumers</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Making-Patches">Making Patches</a>

</div>

<h3 class="section">11.3 Avoiding Common Mistakes</h3>

<p><a name="index-common-mistakes-with-patches-122"></a><a name="index-patch_002c-common-mistakes-123"></a>
When producing a patch for multiple files, apply <samp><span class="command">diff</span></samp> to
directories whose names do not have slashes.  This reduces confusion
when the patch consumer specifies the <samp><span class="option">-p</span><var>number</var></samp> option,
since this option can have surprising results when the old and new
file names have different numbers of slashes.  For example, do not
send a patch with a header that looks like this:

<pre class="example">     diff -Naur v2.0.29/prog/README prog/README
     --- v2.0.29/prog/README	2002-03-10 23:30:39.942229878 -0800
     +++ prog/README	2002-03-17 20:49:32.442260588 -0800
</pre>
   <p class="noindent">because the two file names have different numbers of slashes, and
different versions of <samp><span class="command">patch</span></samp> interpret the file names
differently.  To avoid confusion, send output that looks like this
instead:

<pre class="example">     diff -Naur v2.0.29/prog/README v2.0.30/prog/README
     --- v2.0.29/prog/README	2002-03-10 23:30:39.942229878 -0800
     +++ v2.0.30/prog/README	2002-03-17 20:49:32.442260588 -0800
</pre>
   <p>Make sure you have specified the file names correctly, either in a
context diff header or with an `<samp><span class="samp">Index:</span></samp>' line.  Take care to not send out
reversed patches, since these make people wonder whether they have
already applied the patch.

   <p>Avoid sending patches that compare backup file names like
<samp><span class="file">README.orig</span></samp> or <samp><span class="file">README~</span></samp>, since this might confuse
<samp><span class="command">patch</span></samp> into patching a backup file instead of the real file. 
Instead, send patches that compare the same base file names in
different directories, e.g. <samp><span class="file">old/README</span></samp> and <samp><span class="file">new/README</span></samp>.

   <p>To save people from partially applying a patch before other patches that
should have gone before it, you can make the first patch in the patch
file update a file with a name like <samp><span class="file">patchlevel.h</span></samp> or
<samp><span class="file">version.c</span></samp>, which contains a patch level or version number.  If
the input file contains the wrong version number, <samp><span class="command">patch</span></samp> will
complain immediately.

   <p>An even clearer way to prevent this problem is to put a `<samp><span class="samp">Prereq:</span></samp>'
line before the patch.  If the leading text in the patch file contains a
line that starts with `<samp><span class="samp">Prereq:</span></samp>', <samp><span class="command">patch</span></samp> takes the next word
from that line (normally a version number) and checks whether the next
input file contains that word, preceded and followed by either
white space or a newline.  If not, <samp><span class="command">patch</span></samp> prompts you for
confirmation before proceeding.  This makes it difficult to accidentally
apply patches in the wrong order.

<div class="node">
<p><hr>
<a name="Generating-Smaller-Patches"></a>
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Avoiding-Common-Mistakes">Avoiding Common Mistakes</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Making-Patches">Making Patches</a>

</div>

<h3 class="section">11.4 Generating Smaller Patches</h3>

<p><a name="index-patches_002c-shrinking-124"></a>
The simplest way to generate a patch is to use `<samp><span class="samp">diff -Naur</span></samp>'
(see <a href="#Tips-for-Patch-Producers">Tips for Patch Producers</a>), but you might be able to reduce
the size of the patch by renaming or removing some files before making
the patch.  If the older version of the package contains any files
that the newer version does not, or if any files have been renamed
between the two versions, make a list of <samp><span class="command">rm</span></samp> and <samp><span class="command">mv</span></samp>
commands for the user to execute in the old version directory before
applying the patch.  Then run those commands yourself in the scratch
directory.

   <p>If there are any files that you don't need to include in the patch
because they can easily be rebuilt from other files (for example,
<samp><span class="file">TAGS</span></samp> and output from <samp><span class="command">yacc</span></samp> and <samp><span class="command">makeinfo</span></samp>),
exclude them from the patch by giving <samp><span class="command">diff</span></samp> the <samp><span class="option">-x
</span><var>pattern</var></samp> option (see <a href="#Comparing-Directories">Comparing Directories</a>).  If you want
your patch to modify a derived file because your recipients lack tools
to build it, make sure that the patch for the derived file follows any
patches for files that it depends on, so that the recipients' time
stamps will not confuse <samp><span class="command">make</span></samp>.

   <p>Now you can create the patch using `<samp><span class="samp">diff -Naur</span></samp>'.  Make sure to
specify the scratch directory first and the newer directory second.

   <p>Add to the top of the patch a note telling the user any <samp><span class="command">rm</span></samp> and
<samp><span class="command">mv</span></samp> commands to run before applying the patch.  Then you can
remove the scratch directory.

   <p>You can also shrink the patch size by using fewer lines of context,
but bear in mind that <samp><span class="command">patch</span></samp> typically needs at least two
lines for proper operation when patches do not exactly match the input
files.

<div class="node">
<p><hr>
<a name="Invoking-cmp"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Invoking-diff">Invoking diff</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Making-Patches">Making Patches</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Top">Top</a>

</div>

<h2 class="chapter">12 Invoking <samp><span class="command">cmp</span></samp></h2>

<p><a name="index-invoking-_0040command_007bcmp_007d-125"></a><a name="index-g_t_0040command_007bcmp_007d-invocation-126"></a>
The <samp><span class="command">cmp</span></samp> command compares two files, and if they differ,
tells the first byte and line number where they differ.  Bytes and
lines are numbered starting with 1.  The arguments of <samp><span class="command">cmp</span></samp>
are as follows:

<pre class="example">     cmp <var>options</var>... <var>from-file</var> <span class="roman">[</span><var>to-file</var> <span class="roman">[</span><var>from-skip</var> <span class="roman">[</span><var>to-skip</var><span class="roman">]</span><span class="roman">]</span><span class="roman">]</span>
</pre>
   <p>The file name <samp><span class="file">-</span></samp> is always the standard input.  <samp><span class="command">cmp</span></samp>
also uses the standard input if one file name is omitted.  The
<var>from-skip</var> and <var>to-skip</var> operands specify how many bytes to
ignore at the start of each file; they are equivalent to the
<samp><span class="option">--ignore-initial=</span><var>from-skip</var><span class="option">:</span><var>to-skip</var></samp> option.

   <p>An exit status of 0 means no differences were found, 1 means some
differences were found, and 2 means trouble.

<ul class="menu">
<li><a accesskey="1" href="#cmp-Options">cmp Options</a>:  Summary of options to <samp><span class="command">cmp</span></samp>. 
</ul>

<div class="node">
<p><hr>
<a name="cmp-Options"></a>
Up:&nbsp;<a rel="up" accesskey="u" href="#Invoking-cmp">Invoking cmp</a>

</div>

<h3 class="section">12.1 Options to <samp><span class="command">cmp</span></samp></h3>

<p><a name="index-g_t_0040command_007bcmp_007d-options-127"></a><a name="index-options-for-_0040command_007bcmp_007d-128"></a>
Below is a summary of all of the options that <span class="sc">gnu</span> <samp><span class="command">cmp</span></samp> accepts. 
Most options have two equivalent names, one of which is a single letter
preceded by `<samp><span class="samp">-</span></samp>', and the other of which is a long name preceded by
`<samp><span class="samp">--</span></samp>'.  Multiple single letter options (unless they take an
argument) can be combined into a single command line word: <samp><span class="option">-bl</span></samp> is
equivalent to <samp><span class="option">-b -l</span></samp>.

     <dl>
<dt><samp><span class="option">-b</span></samp><dt><samp><span class="option">--print-bytes</span></samp><dd>Print the differing bytes.  Display control bytes as a
`<samp><span class="samp">^</span></samp>' followed by a letter of the alphabet and precede bytes
that have the high bit set with `<samp><span class="samp">M-</span></samp>' (which stands for &ldquo;meta&rdquo;).

     <br><dt><samp><span class="option">--help</span></samp><dd>Output a summary of usage and then exit.

     <br><dt><samp><span class="option">-i </span><var>skip</var></samp><dt><samp><span class="option">--ignore-initial=</span><var>skip</var></samp><dd>Ignore any differences in the first <var>skip</var> bytes of the input
files.  Treat files with fewer than <var>skip</var> bytes as if they are
empty.  If <var>skip</var> is of the form
<samp><var>from-skip</var><span class="option">:</span><var>to-skip</var></samp>, skip the first <var>from-skip</var>
bytes of the first input file and the first <var>to-skip</var> bytes of the
second.

     <br><dt><samp><span class="option">-l</span></samp><dt><samp><span class="option">--verbose</span></samp><dd>Print the (decimal) byte numbers and (octal) values of all differing bytes.

     <br><dt><samp><span class="option">-n </span><var>count</var></samp><dt><samp><span class="option">--bytes=</span><var>count</var></samp><dd>Compare at most <var>count</var> input bytes.

     <br><dt><samp><span class="option">-s</span></samp><dt><samp><span class="option">--quiet</span></samp><dt><samp><span class="option">--silent</span></samp><dd>Do not print anything; only return an exit status indicating whether
the files differ.

     <br><dt><samp><span class="option">-v</span></samp><dt><samp><span class="option">--version</span></samp><dd>Output version information and then exit. 
</dl>

   <p>In the above table, operands that are byte counts are normally
decimal, but may be preceded by `<samp><span class="samp">0</span></samp>' for octal and `<samp><span class="samp">0x</span></samp>' for
hexadecimal.

   <p>A byte count can be followed by a suffix to specify a multiple of that
count; in this case an omitted integer is understood to be 1.  A bare
size letter, or one followed by `<samp><span class="samp">iB</span></samp>', specifies a multiple using
powers of 1024.  A size letter followed by `<samp><span class="samp">B</span></samp>' specifies powers
of 1000 instead.  For example, <samp><span class="option">-n 4M</span></samp> and <samp><span class="option">-n 4MiB</span></samp> are
equivalent to <samp><span class="option">-n 4194304</span></samp>, whereas <samp><span class="option">-n 4MB</span></samp> is
equivalent to <samp><span class="option">-n 4000000</span></samp>.  This notation is upward compatible
with the <a href="http://www.bipm.fr/enus/3_SI/si-prefixes.html">SI prefixes</a> for decimal multiples and with the
<a href="http://physics.nist.gov/cuu/Units/binary.html">IEC 60027-2 prefixes for binary multiples</a>.

   <p>The following suffixes are defined.  Large sizes like <code>1Y</code> may be
rejected by your computer due to limitations of its arithmetic.

     <dl>
<dt>`<samp><span class="samp">kB</span></samp>'<dd><a name="index-kilobyte_002c-definition-of-129"></a>kilobyte: 10^3 = 1000. 
<br><dt>`<samp><span class="samp">k</span></samp>'<dt>`<samp><span class="samp">K</span></samp>'<dt>`<samp><span class="samp">KiB</span></samp>'<dd><a name="index-kibibyte_002c-definition-of-130"></a>kibibyte: 2^10 = 1024.  `<samp><span class="samp">K</span></samp>' is special: the SI prefix is
`<samp><span class="samp">k</span></samp>' and the IEC 60027-2 prefix is `<samp><span class="samp">Ki</span></samp>', but tradition and
<span class="sc">posix</span> use `<samp><span class="samp">k</span></samp>' to mean `<samp><span class="samp">KiB</span></samp>'. 
<br><dt>`<samp><span class="samp">MB</span></samp>'<dd><a name="index-megabyte_002c-definition-of-131"></a>megabyte: 10^6 = 1,000,000. 
<br><dt>`<samp><span class="samp">M</span></samp>'<dt>`<samp><span class="samp">MiB</span></samp>'<dd><a name="index-mebibyte_002c-definition-of-132"></a>mebibyte: 2^20 = 1,048,576. 
<br><dt>`<samp><span class="samp">GB</span></samp>'<dd><a name="index-gigabyte_002c-definition-of-133"></a>gigabyte: 10^9 = 1,000,000,000. 
<br><dt>`<samp><span class="samp">G</span></samp>'<dt>`<samp><span class="samp">GiB</span></samp>'<dd><a name="index-gibibyte_002c-definition-of-134"></a>gibibyte: 2^30 = 1,073,741,824. 
<br><dt>`<samp><span class="samp">TB</span></samp>'<dd><a name="index-terabyte_002c-definition-of-135"></a>terabyte:  10^12 = 1,000,000,000,000. 
<br><dt>`<samp><span class="samp">T</span></samp>'<dt>`<samp><span class="samp">TiB</span></samp>'<dd><a name="index-tebibyte_002c-definition-of-136"></a>tebibyte: 2^40 = 1,099,511,627,776. 
<br><dt>`<samp><span class="samp">PB</span></samp>'<dd><a name="index-petabyte_002c-definition-of-137"></a>petabyte: 10^15 = 1,000,000,000,000,000. 
<br><dt>`<samp><span class="samp">P</span></samp>'<dt>`<samp><span class="samp">PiB</span></samp>'<dd><a name="index-pebibyte_002c-definition-of-138"></a>pebibyte: 2^50 = 1,125,899,906,842,624. 
<br><dt>`<samp><span class="samp">EB</span></samp>'<dd><a name="index-exabyte_002c-definition-of-139"></a>exabyte: 10^18 = 1,000,000,000,000,000,000. 
<br><dt>`<samp><span class="samp">E</span></samp>'<dt>`<samp><span class="samp">EiB</span></samp>'<dd><a name="index-exbibyte_002c-definition-of-140"></a>exbibyte: 2^60 = 1,152,921,504,606,846,976. 
<br><dt>`<samp><span class="samp">ZB</span></samp>'<dd><a name="index-zettabyte_002c-definition-of-141"></a>zettabyte: 10^21 = 1,000,000,000,000,000,000,000
<br><dt>`<samp><span class="samp">Z</span></samp>'<dt>`<samp><span class="samp">ZiB</span></samp>'<dd>2^70 = 1,180,591,620,717,411,303,424. 
(`<samp><span class="samp">Zi</span></samp>' is a GNU extension to IEC 60027-2.) 
<br><dt>`<samp><span class="samp">YB</span></samp>'<dd><a name="index-yottabyte_002c-definition-of-142"></a>yottabyte: 10^24 = 1,000,000,000,000,000,000,000,000. 
<br><dt>`<samp><span class="samp">Y</span></samp>'<dt>`<samp><span class="samp">YiB</span></samp>'<dd>2^80 = 1,208,925,819,614,629,174,706,176. 
(`<samp><span class="samp">Yi</span></samp>' is a GNU extension to IEC 60027-2.) 
</dl>

<div class="node">
<p><hr>
<a name="Invoking-diff"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Invoking-diff3">Invoking diff3</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Invoking-cmp">Invoking cmp</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Top">Top</a>

</div>

<h2 class="chapter">13 Invoking <samp><span class="command">diff</span></samp></h2>

<p><a name="index-invoking-_0040command_007bdiff_007d-143"></a><a name="index-g_t_0040command_007bdiff_007d-invocation-144"></a>
The format for running the <samp><span class="command">diff</span></samp> command is:

<pre class="example">     diff <var>options</var>... <var>files</var>...
</pre>
   <p>In the simplest case, two file names <var>from-file</var> and
<var>to-file</var> are given, and <samp><span class="command">diff</span></samp> compares the contents of
<var>from-file</var> and <var>to-file</var>.  A file name of <samp><span class="file">-</span></samp> stands for
text read from the standard input.  As a special case, `<samp><span class="samp">diff - -</span></samp>'
compares a copy of standard input to itself.

   <p>If one file is a directory and the other is not, <samp><span class="command">diff</span></samp> compares
the file in the directory whose name is that of the non-directory. 
The non-directory file must not be <samp><span class="file">-</span></samp>.

   <p>If two file names are given and both are directories,
<samp><span class="command">diff</span></samp> compares corresponding files in both directories, in
alphabetical order; this comparison is not recursive unless the
<samp><span class="option">-r</span></samp> or <samp><span class="option">--recursive</span></samp> option is given.  <samp><span class="command">diff</span></samp> never
compares the actual contents of a directory as if it were a file.  The
file that is fully specified may not be standard input, because standard
input is nameless and the notion of &ldquo;file with the same name&rdquo; does not
apply.

   <p>If the <samp><span class="option">--from-file=</span><var>file</var></samp> option is given, the number of
file names is arbitrary, and <var>file</var> is compared to each named file. 
Similarly, if the <samp><span class="option">--to-file=</span><var>file</var></samp> option is given, each
named file is compared to <var>file</var>.

   <p><samp><span class="command">diff</span></samp> options begin with `<samp><span class="samp">-</span></samp>', so normally file names
may not begin with `<samp><span class="samp">-</span></samp>'.  However, <samp><span class="option">--</span></samp> as an
argument by itself treats the remaining arguments as file names even if
they begin with `<samp><span class="samp">-</span></samp>'.

   <p>An exit status of 0 means no differences were found, 1 means some
differences were found, and 2 means trouble.

<ul class="menu">
<li><a accesskey="1" href="#diff-Options">diff Options</a>:  Summary of options to <samp><span class="command">diff</span></samp>. 
</ul>

<div class="node">
<p><hr>
<a name="diff-Options"></a>
Up:&nbsp;<a rel="up" accesskey="u" href="#Invoking-diff">Invoking diff</a>

</div>

<h3 class="section">13.1 Options to <samp><span class="command">diff</span></samp></h3>

<p><a name="index-g_t_0040command_007bdiff_007d-options-145"></a><a name="index-options-for-_0040command_007bdiff_007d-146"></a>
Below is a summary of all of the options that <span class="sc">gnu</span> <samp><span class="command">diff</span></samp> accepts. 
Most options have two equivalent names, one of which is a single letter
preceded by `<samp><span class="samp">-</span></samp>', and the other of which is a long name preceded by
`<samp><span class="samp">--</span></samp>'.  Multiple single letter options (unless they take an
argument) can be combined into a single command line word: <samp><span class="option">-ac</span></samp> is
equivalent to <samp><span class="option">-a -c</span></samp>.  Long named options can be abbreviated to
any unique prefix of their name.  Brackets ([ and ]) indicate that an
option takes an optional argument.

     <dl>
<dt><samp><span class="option">-a</span></samp><dt><samp><span class="option">--text</span></samp><dd>Treat all files as text and compare them line-by-line, even if they
do not seem to be text.  See <a href="#Binary">Binary</a>.

     <br><dt><samp><span class="option">-b</span></samp><dt><samp><span class="option">--ignore-space-change</span></samp><dd>Ignore changes in amount of white space.  See <a href="#White-Space">White Space</a>.

     <br><dt><samp><span class="option">-B</span></samp><dt><samp><span class="option">--ignore-blank-lines</span></samp><dd>Ignore changes that just insert or delete blank lines.  See <a href="#Blank-Lines">Blank Lines</a>.

     <br><dt><samp><span class="option">--binary</span></samp><dd>Read and write data in binary mode.  See <a href="#Binary">Binary</a>.

     <br><dt><samp><span class="option">-c</span></samp><dd>Use the context output format, showing three lines of context. 
See <a href="#Context-Format">Context Format</a>.

     <br><dt><samp><span class="option">-C </span><var>lines</var></samp><dt><samp><span class="option">--context[=</span><var>lines</var><span class="option">]</span></samp><dd>Use the context output format, showing <var>lines</var> (an integer) lines of
context, or three if <var>lines</var> is not given.  See <a href="#Context-Format">Context Format</a>. 
For proper operation, <samp><span class="command">patch</span></samp> typically needs at least two lines of
context.

     <p>On older systems, <samp><span class="command">diff</span></samp> supports an obsolete option
<samp><span class="option">-</span><var>lines</var></samp> that has effect when combined with <samp><span class="option">-c</span></samp>
or <samp><span class="option">-p</span></samp>.  <span class="sc">posix</span> 1003.1-2001 (see <a href="#Standards-conformance">Standards conformance</a>) does not allow this; use <samp><span class="option">-C </span><var>lines</var></samp>
instead.

     <br><dt><samp><span class="option">--changed-group-format=</span><var>format</var></samp><dd>Use <var>format</var> to output a line group containing differing lines from
both files in if-then-else format.  See <a href="#Line-Group-Formats">Line Group Formats</a>.

     <br><dt><samp><span class="option">-d</span></samp><dt><samp><span class="option">--minimal</span></samp><dd>Change the algorithm perhaps find a smaller set of changes.  This makes
<samp><span class="command">diff</span></samp> slower (sometimes much slower).  See <a href="#diff-Performance">diff Performance</a>.

     <br><dt><samp><span class="option">-D </span><var>name</var></samp><dt><samp><span class="option">--ifdef=</span><var>name</var></samp><dd>Make merged `<samp><span class="samp">#ifdef</span></samp>' format output, conditional on the preprocessor
macro <var>name</var>.  See <a href="#If_002dthen_002delse">If-then-else</a>.

     <br><dt><samp><span class="option">-e</span></samp><dt><samp><span class="option">--ed</span></samp><dd>Make output that is a valid <samp><span class="command">ed</span></samp> script.  See <a href="#ed-Scripts">ed Scripts</a>.

     <br><dt><samp><span class="option">-E</span></samp><dt><samp><span class="option">--ignore-tab-expansion</span></samp><dd>Ignore changes due to tab expansion. 
See <a href="#White-Space">White Space</a>.

     <br><dt><samp><span class="option">-f</span></samp><dt><samp><span class="option">--forward-ed</span></samp><dd>Make output that looks vaguely like an <samp><span class="command">ed</span></samp> script but has changes
in the order they appear in the file.  See <a href="#Forward-ed">Forward ed</a>.

     <br><dt><samp><span class="option">-F </span><var>regexp</var></samp><dt><samp><span class="option">--show-function-line=</span><var>regexp</var></samp><dd>In context and unified format, for each hunk of differences, show some
of the last preceding line that matches <var>regexp</var>.  See <a href="#Specified-Headings">Specified Headings</a>.

     <br><dt><samp><span class="option">--from-file=</span><var>file</var></samp><dd>Compare <var>file</var> to each operand; <var>file</var> may be a directory.

     <br><dt><samp><span class="option">--help</span></samp><dd>Output a summary of usage and then exit.

     <br><dt><samp><span class="option">--horizon-lines=</span><var>lines</var></samp><dd>Do not discard the last <var>lines</var> lines of the common prefix
and the first <var>lines</var> lines of the common suffix. 
See <a href="#diff-Performance">diff Performance</a>.

     <br><dt><samp><span class="option">-i</span></samp><dt><samp><span class="option">--ignore-case</span></samp><dd>Ignore changes in case; consider upper- and lower-case letters
equivalent.  See <a href="#Case-Folding">Case Folding</a>.

     <br><dt><samp><span class="option">-I </span><var>regexp</var></samp><dt><samp><span class="option">--ignore-matching-lines=</span><var>regexp</var></samp><dd>Ignore changes that just insert or delete lines that match <var>regexp</var>. 
See <a href="#Specified-Folding">Specified Folding</a>.

     <br><dt><samp><span class="option">--ignore-file-name-case</span></samp><dd>Ignore case when comparing file names during recursive comparison. 
See <a href="#Comparing-Directories">Comparing Directories</a>.

     <br><dt><samp><span class="option">-l</span></samp><dt><samp><span class="option">--paginate</span></samp><dd>Pass the output through <samp><span class="command">pr</span></samp> to paginate it.  See <a href="#Pagination">Pagination</a>.

     <br><dt><samp><span class="option">--label=</span><var>label</var></samp><dd>Use <var>label</var> instead of the file name in the context format
(see <a href="#Context-Format">Context Format</a>) and unified format (see <a href="#Unified-Format">Unified Format</a>)
headers.  See <a href="#RCS">RCS</a>.

     <br><dt><samp><span class="option">--left-column</span></samp><dd>Print only the left column of two common lines in side by side format. 
See <a href="#Side-by-Side-Format">Side by Side Format</a>.

     <br><dt><samp><span class="option">--line-format=</span><var>format</var></samp><dd>Use <var>format</var> to output all input lines in if-then-else format. 
See <a href="#Line-Formats">Line Formats</a>.

     <br><dt><samp><span class="option">-n</span></samp><dt><samp><span class="option">--rcs</span></samp><dd>Output <span class="sc">rcs</span>-format diffs; like <samp><span class="option">-f</span></samp> except that each command
specifies the number of lines affected.  See <a href="#RCS">RCS</a>.

     <br><dt><samp><span class="option">-N</span></samp><dt><samp><span class="option">--new-file</span></samp><dd>In directory comparison, if a file is found in only one directory,
treat it as present but empty in the other directory.  See <a href="#Comparing-Directories">Comparing Directories</a>.

     <br><dt><samp><span class="option">--new-group-format=</span><var>format</var></samp><dd>Use <var>format</var> to output a group of lines taken from just the second
file in if-then-else format.  See <a href="#Line-Group-Formats">Line Group Formats</a>.

     <br><dt><samp><span class="option">--new-line-format=</span><var>format</var></samp><dd>Use <var>format</var> to output a line taken from just the second file in
if-then-else format.  See <a href="#Line-Formats">Line Formats</a>.

     <br><dt><samp><span class="option">--old-group-format=</span><var>format</var></samp><dd>Use <var>format</var> to output a group of lines taken from just the first
file in if-then-else format.  See <a href="#Line-Group-Formats">Line Group Formats</a>.

     <br><dt><samp><span class="option">--old-line-format=</span><var>format</var></samp><dd>Use <var>format</var> to output a line taken from just the first file in
if-then-else format.  See <a href="#Line-Formats">Line Formats</a>.

     <br><dt><samp><span class="option">-p</span></samp><dt><samp><span class="option">--show-c-function</span></samp><dd>Show which C function each change is in.  See <a href="#C-Function-Headings">C Function Headings</a>.

     <br><dt><samp><span class="option">-q</span></samp><dt><samp><span class="option">--brief</span></samp><dd>Report only whether the files differ, not the details of the
differences.  See <a href="#Brief">Brief</a>.

     <br><dt><samp><span class="option">-r</span></samp><dt><samp><span class="option">--recursive</span></samp><dd>When comparing directories, recursively compare any subdirectories
found.  See <a href="#Comparing-Directories">Comparing Directories</a>.

     <br><dt><samp><span class="option">-s</span></samp><dt><samp><span class="option">--report-identical-files</span></samp><dd>Report when two files are the same.  See <a href="#Comparing-Directories">Comparing Directories</a>.

     <br><dt><samp><span class="option">-S </span><var>file</var></samp><dt><samp><span class="option">--starting-file=</span><var>file</var></samp><dd>When comparing directories, start with the file <var>file</var>.  This is
used for resuming an aborted comparison.  See <a href="#Comparing-Directories">Comparing Directories</a>.

     <br><dt><samp><span class="option">--speed-large-files</span></samp><dd>Use heuristics to speed handling of large files that have numerous
scattered small changes.  See <a href="#diff-Performance">diff Performance</a>.

     <br><dt><samp><span class="option">--strip-trailing-cr</span></samp><dd>Strip any trailing carriage return at the end of an input line. 
See <a href="#Binary">Binary</a>.

     <br><dt><samp><span class="option">--suppress-common-lines</span></samp><dd>Do not print common lines in side by side format. 
See <a href="#Side-by-Side-Format">Side by Side Format</a>.

     <br><dt><samp><span class="option">-t</span></samp><dt><samp><span class="option">--expand-tabs</span></samp><dd>Expand tabs to spaces in the output, to preserve the alignment of tabs
in the input files.  See <a href="#Tabs">Tabs</a>.

     <br><dt><samp><span class="option">-T</span></samp><dt><samp><span class="option">--initial-tab</span></samp><dd>Output a tab rather than a space before the text of a line in normal or
context format.  This causes the alignment of tabs in the line to look
normal.  See <a href="#Tabs">Tabs</a>.

     <br><dt><samp><span class="option">--to-file=</span><var>file</var></samp><dd>Compare each operand to <var>file</var>; <var>file</var> may be a directory.

     <br><dt><samp><span class="option">-u</span></samp><dd>Use the unified output format, showing three lines of context. 
See <a href="#Unified-Format">Unified Format</a>.

     <br><dt><samp><span class="option">--unchanged-group-format=</span><var>format</var></samp><dd>Use <var>format</var> to output a group of common lines taken from both files
in if-then-else format.  See <a href="#Line-Group-Formats">Line Group Formats</a>.

     <br><dt><samp><span class="option">--unchanged-line-format=</span><var>format</var></samp><dd>Use <var>format</var> to output a line common to both files in if-then-else
format.  See <a href="#Line-Formats">Line Formats</a>.

     <br><dt><samp><span class="option">--unidirectional-new-file</span></samp><dd>When comparing directories, if a file appears only in the second
directory of the two, treat it as present but empty in the other. 
See <a href="#Comparing-Directories">Comparing Directories</a>.

     <br><dt><samp><span class="option">-U </span><var>lines</var></samp><dt><samp><span class="option">--unified[=</span><var>lines</var><span class="option">]</span></samp><dd>Use the unified output format, showing <var>lines</var> (an integer) lines of
context, or three if <var>lines</var> is not given.  See <a href="#Unified-Format">Unified Format</a>. 
For proper operation, <samp><span class="command">patch</span></samp> typically needs at least two lines of
context.

     <p>On older systems, <samp><span class="command">diff</span></samp> supports an obsolete option
<samp><span class="option">-</span><var>lines</var></samp> that has effect when combined with <samp><span class="option">-u</span></samp>. 
<span class="sc">posix</span> 1003.1-2001 (see <a href="#Standards-conformance">Standards conformance</a>) does not allow
this; use <samp><span class="option">-U </span><var>lines</var></samp> instead.

     <br><dt><samp><span class="option">-v</span></samp><dt><samp><span class="option">--version</span></samp><dd>Output version information and then exit.

     <br><dt><samp><span class="option">-w</span></samp><dt><samp><span class="option">--ignore-all-space</span></samp><dd>Ignore white space when comparing lines.  See <a href="#White-Space">White Space</a>.

     <br><dt><samp><span class="option">-W </span><var>columns</var></samp><dt><samp><span class="option">--width=</span><var>columns</var></samp><dd>Output at most <var>columns</var> (default 130) print columns per line in
side by side format.  See <a href="#Side-by-Side-Format">Side by Side Format</a>.

     <br><dt><samp><span class="option">-x </span><var>pattern</var></samp><dt><samp><span class="option">--exclude=</span><var>pattern</var></samp><dd>When comparing directories, ignore files and subdirectories whose basenames
match <var>pattern</var>.  See <a href="#Comparing-Directories">Comparing Directories</a>.

     <br><dt><samp><span class="option">-X </span><var>file</var></samp><dt><samp><span class="option">--exclude-from=</span><var>file</var></samp><dd>When comparing directories, ignore files and subdirectories whose basenames
match any pattern contained in <var>file</var>.  See <a href="#Comparing-Directories">Comparing Directories</a>.

     <br><dt><samp><span class="option">-y</span></samp><dt><samp><span class="option">--side-by-side</span></samp><dd>Use the side by side output format.  See <a href="#Side-by-Side-Format">Side by Side Format</a>. 
</dl>

<div class="node">
<p><hr>
<a name="Invoking-diff3"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Invoking-patch">Invoking patch</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Invoking-diff">Invoking diff</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Top">Top</a>

</div>

<h2 class="chapter">14 Invoking <samp><span class="command">diff3</span></samp></h2>

<p><a name="index-invoking-_0040command_007bdiff3_007d-147"></a><a name="index-g_t_0040command_007bdiff3_007d-invocation-148"></a>
The <samp><span class="command">diff3</span></samp> command compares three files and outputs descriptions
of their differences.  Its arguments are as follows:

<pre class="example">     diff3 <var>options</var>... <var>mine</var> <var>older</var> <var>yours</var>
</pre>
   <p>The files to compare are <var>mine</var>, <var>older</var>, and <var>yours</var>. 
At most one of these three file names may be <samp><span class="file">-</span></samp>,
which tells <samp><span class="command">diff3</span></samp> to read the standard input for that file.

   <p>An exit status of 0 means <samp><span class="command">diff3</span></samp> was successful, 1 means some
conflicts were found, and 2 means trouble.

<ul class="menu">
<li><a accesskey="1" href="#diff3-Options">diff3 Options</a>:  Summary of options to <samp><span class="command">diff3</span></samp>. 
</ul>

<div class="node">
<p><hr>
<a name="diff3-Options"></a>
Up:&nbsp;<a rel="up" accesskey="u" href="#Invoking-diff3">Invoking diff3</a>

</div>

<h3 class="section">14.1 Options to <samp><span class="command">diff3</span></samp></h3>

<p><a name="index-g_t_0040command_007bdiff3_007d-options-149"></a><a name="index-options-for-_0040command_007bdiff3_007d-150"></a>
Below is a summary of all of the options that <span class="sc">gnu</span> <samp><span class="command">diff3</span></samp>
accepts.  Multiple single letter options (unless they take an argument)
can be combined into a single command line argument.

     <dl>
<dt><samp><span class="option">-a</span></samp><dt><samp><span class="option">--text</span></samp><dd>Treat all files as text and compare them line-by-line, even if they
do not appear to be text.  See <a href="#Binary">Binary</a>.

     <br><dt><samp><span class="option">-A</span></samp><dt><samp><span class="option">--show-all</span></samp><dd>Incorporate all unmerged changes from <var>older</var> to <var>yours</var> into
<var>mine</var>, surrounding conflicts with bracket lines. 
See <a href="#Marking-Conflicts">Marking Conflicts</a>.

     <br><dt><samp><span class="option">--diff-program=</span><var>program</var></samp><dd>Use the compatible comparison program <var>program</var> to compare files
instead of <samp><span class="command">diff</span></samp>.

     <br><dt><samp><span class="option">-e</span></samp><dt><samp><span class="option">--ed</span></samp><dd>Generate an <samp><span class="command">ed</span></samp> script that incorporates all the changes from
<var>older</var> to <var>yours</var> into <var>mine</var>.  See <a href="#Which-Changes">Which Changes</a>.

     <br><dt><samp><span class="option">-E</span></samp><dt><samp><span class="option">--show-overlap</span></samp><dd>Like <samp><span class="option">-e</span></samp>, except bracket lines from overlapping changes' first
and third files. 
See <a href="#Marking-Conflicts">Marking Conflicts</a>. 
With <samp><span class="option">-E</span></samp>, an overlapping change looks like this:

     <pre class="example">          &lt;&lt;&lt;&lt;&lt;&lt;&lt; <var>mine</var>
          <span class="roman">lines from </span><var>mine</var>
          =======
          <span class="roman">lines from </span><var>yours</var>
          &gt;&gt;&gt;&gt;&gt;&gt;&gt; <var>yours</var>
     </pre>
     <br><dt><samp><span class="option">--help</span></samp><dd>Output a summary of usage and then exit.

     <br><dt><samp><span class="option">-i</span></samp><dd>Generate `<samp><span class="samp">w</span></samp>' and `<samp><span class="samp">q</span></samp>' commands at the end of the <samp><span class="command">ed</span></samp>
script for System V compatibility.  This option must be combined with
one of the <samp><span class="option">-AeExX3</span></samp> options, and may not be combined with <samp><span class="option">-m</span></samp>. 
See <a href="#Saving-the-Changed-File">Saving the Changed File</a>.

     <br><dt><samp><span class="option">-L </span><var>label</var></samp><dt><samp><span class="option">--label=</span><var>label</var></samp><dd>Use the label <var>label</var> for the brackets output by the <samp><span class="option">-A</span></samp>,
<samp><span class="option">-E</span></samp> and <samp><span class="option">-X</span></samp> options.  This option may be given up to three
times, one for each input file.  The default labels are the names of
the input files.  Thus `<samp><span class="samp">diff3 -L X -L Y -L Z -m A B C</span></samp>' acts like
`<samp><span class="samp">diff3 -m A B C</span></samp>', except that the output looks like it came from
files named `<samp><span class="samp">X</span></samp>', `<samp><span class="samp">Y</span></samp>' and `<samp><span class="samp">Z</span></samp>' rather than from files
named `<samp><span class="samp">A</span></samp>', `<samp><span class="samp">B</span></samp>' and `<samp><span class="samp">C</span></samp>'.  See <a href="#Marking-Conflicts">Marking Conflicts</a>.

     <br><dt><samp><span class="option">-m</span></samp><dt><samp><span class="option">--merge</span></samp><dd>Apply the edit script to the first file and send the result to standard
output.  Unlike piping the output from <samp><span class="command">diff3</span></samp> to <samp><span class="command">ed</span></samp>, this
works even for binary files and incomplete lines.  <samp><span class="option">-A</span></samp> is assumed
if no edit script option is specified.  See <a href="#Bypassing-ed">Bypassing ed</a>.

     <br><dt><samp><span class="option">-T</span></samp><dt><samp><span class="option">--initial-tab</span></samp><dd>Output a tab rather than two spaces before the text of a line in normal format. 
This causes the alignment of tabs in the line to look normal.  See <a href="#Tabs">Tabs</a>.

     <br><dt><samp><span class="option">-v</span></samp><dt><samp><span class="option">--version</span></samp><dd>Output version information and then exit.

     <br><dt><samp><span class="option">-x</span></samp><dt><samp><span class="option">--overlap-only</span></samp><dd>Like <samp><span class="option">-e</span></samp>, except output only the overlapping changes. 
See <a href="#Which-Changes">Which Changes</a>.

     <br><dt><samp><span class="option">-X</span></samp><dd>Like <samp><span class="option">-E</span></samp>, except output only the overlapping changes. 
In other words, like <samp><span class="option">-x</span></samp>, except bracket changes as in <samp><span class="option">-E</span></samp>. 
See <a href="#Marking-Conflicts">Marking Conflicts</a>.

     <br><dt><samp><span class="option">-3</span></samp><dt><samp><span class="option">--easy-only</span></samp><dd>Like <samp><span class="option">-e</span></samp>, except output only the nonoverlapping changes. 
See <a href="#Which-Changes">Which Changes</a>. 
</dl>

<div class="node">
<p><hr>
<a name="Invoking-patch"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Invoking-sdiff">Invoking sdiff</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Invoking-diff3">Invoking diff3</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Top">Top</a>

</div>

<h2 class="chapter">15 Invoking <samp><span class="command">patch</span></samp></h2>

<p><a name="index-invoking-_0040command_007bpatch_007d-151"></a><a name="index-g_t_0040command_007bpatch_007d-invocation-152"></a>
Normally <samp><span class="command">patch</span></samp> is invoked like this:

<pre class="example">     patch &lt;<var>patchfile</var>
</pre>
   <p>The full format for invoking <samp><span class="command">patch</span></samp> is:

<pre class="example">     patch <var>options</var>... <span class="roman">[</span><var>origfile</var> <span class="roman">[</span><var>patchfile</var><span class="roman">]</span><span class="roman">]</span>
</pre>
   <p>You can also specify where to read the patch from with the <samp><span class="option">-i
</span><var>patchfile</var></samp> or <samp><span class="option">--input=</span><var>patchfile</var></samp> option. 
If you do not specify <var>patchfile</var>, or if <var>patchfile</var> is
<samp><span class="file">-</span></samp>, <samp><span class="command">patch</span></samp> reads the patch (that is, the <samp><span class="command">diff</span></samp> output)
from the standard input.

   <p>If you do not specify an input file on the command line, <samp><span class="command">patch</span></samp>
tries to intuit from the <dfn>leading text</dfn> (any text in the patch
that comes before the <samp><span class="command">diff</span></samp> output) which file to edit. 
See <a href="#Multiple-Patches">Multiple Patches</a>.

   <p>By default, <samp><span class="command">patch</span></samp> replaces the original input file with the
patched version, possibly after renaming the original file into a
backup file (see <a href="#Backup-Names">Backup Names</a>, for a description of how
<samp><span class="command">patch</span></samp> names backup files).  You can also specify where to
put the output with the <samp><span class="option">-o </span><var>file</var></samp> or
<samp><span class="option">--output=</span><var>file</var></samp> option; however, do not use this option
if <var>file</var> is one of the input files.

<ul class="menu">
<li><a accesskey="1" href="#patch-Options">patch Options</a>:      Summary table of options to <samp><span class="command">patch</span></samp>. 
</ul>

<div class="node">
<p><hr>
<a name="patch-Options"></a>
Up:&nbsp;<a rel="up" accesskey="u" href="#Invoking-patch">Invoking patch</a>

</div>

<h3 class="section">15.1 Options to <samp><span class="command">patch</span></samp></h3>

<p><a name="index-g_t_0040command_007bpatch_007d-options-153"></a><a name="index-options-for-_0040command_007bpatch_007d-154"></a>
Here is a summary of all of the options that <span class="sc">gnu</span> <samp><span class="command">patch</span></samp>
accepts.  See <a href="#patch-and-Tradition">patch and Tradition</a>, for which of these options are
safe to use in older versions of <samp><span class="command">patch</span></samp>.

   <p>Multiple single-letter options that do not take an argument can be
combined into a single command line argument with only one dash.

     <dl>
<dt><samp><span class="option">-b</span></samp><dt><samp><span class="option">--backup</span></samp><dd>Back up the original contents of each file, even if backups would
normally not be made.  See <a href="#Backups">Backups</a>.

     <br><dt><samp><span class="option">-B </span><var>prefix</var></samp><dt><samp><span class="option">--prefix=</span><var>prefix</var></samp><dd>Prepend <var>prefix</var> to backup file names.  See <a href="#Backup-Names">Backup Names</a>.

     <br><dt><samp><span class="option">--backup-if-mismatch</span></samp><dd>Back up the original contents of each file if the patch does not
exactly match the file.  This is the default behavior when not
conforming to <span class="sc">posix</span>.  See <a href="#Backups">Backups</a>.

     <br><dt><samp><span class="option">--binary</span></samp><dd>Read and write all files in binary mode, except for standard output
and <samp><span class="file">/dev/tty</span></samp>.  This option has no effect on
<span class="sc">posix</span>-conforming systems like <span class="sc">gnu</span>/Linux.  On systems where
this option makes a difference, the patch should be generated by
`<samp><span class="samp">diff -a --binary</span></samp>'.  See <a href="#Binary">Binary</a>.

     <br><dt><samp><span class="option">-c</span></samp><dt><samp><span class="option">--context</span></samp><dd>Interpret the patch file as a context diff.  See <a href="#patch-Input">patch Input</a>.

     <br><dt><samp><span class="option">-d </span><var>directory</var></samp><dt><samp><span class="option">--directory=</span><var>directory</var></samp><dd>Make directory <var>directory</var> the current directory for interpreting
both file names in the patch file, and file names given as arguments to
other options.  See <a href="#patch-Directories">patch Directories</a>.

     <br><dt><samp><span class="option">-D </span><var>name</var></samp><dt><samp><span class="option">--ifdef=</span><var>name</var></samp><dd>Make merged if-then-else output using <var>name</var>.  See <a href="#If_002dthen_002delse">If-then-else</a>.

     <br><dt><samp><span class="option">--dry-run</span></samp><dd>Print the results of applying the patches without actually changing
any files.  See <a href="#Dry-Runs">Dry Runs</a>.

     <br><dt><samp><span class="option">-e</span></samp><dt><samp><span class="option">--ed</span></samp><dd>Interpret the patch file as an <samp><span class="command">ed</span></samp> script.  See <a href="#patch-Input">patch Input</a>.

     <br><dt><samp><span class="option">-E</span></samp><dt><samp><span class="option">--remove-empty-files</span></samp><dd>Remove output files that are empty after the patches have been applied. 
See <a href="#Creating-and-Removing">Creating and Removing</a>.

     <br><dt><samp><span class="option">-f</span></samp><dt><samp><span class="option">--force</span></samp><dd>Assume that the user knows exactly what he or she is doing, and do not
ask any questions.  See <a href="#patch-Messages">patch Messages</a>.

     <br><dt><samp><span class="option">-F </span><var>lines</var></samp><dt><samp><span class="option">--fuzz=</span><var>lines</var></samp><dd>Set the maximum fuzz factor to <var>lines</var>.  See <a href="#Inexact">Inexact</a>.

     <br><dt><samp><span class="option">-g </span><var>num</var></samp><dt><samp><span class="option">--get=</span><var>num</var></samp><dd>If <var>num</var> is positive, get input files from a revision control
system as necessary; if zero, do not get the files; if negative, ask
the user whether to get the files.  See <a href="#Revision-Control">Revision Control</a>.

     <br><dt><samp><span class="option">--help</span></samp><dd>Output a summary of usage and then exit.

     <br><dt><samp><span class="option">-i </span><var>patchfile</var></samp><dt><samp><span class="option">--input=</span><var>patchfile</var></samp><dd>Read the patch from <var>patchfile</var> rather than from standard input. 
See <a href="#patch-Options">patch Options</a>.

     <br><dt><samp><span class="option">-l</span></samp><dt><samp><span class="option">--ignore-white-space</span></samp><dd>Let any sequence of blanks (spaces or tabs) in the patch file match
any sequence of blanks in the input file.  See <a href="#Changed-White-Space">Changed White Space</a>.

     <br><dt><samp><span class="option">-n</span></samp><dt><samp><span class="option">--normal</span></samp><dd>Interpret the patch file as a normal diff.  See <a href="#patch-Input">patch Input</a>.

     <br><dt><samp><span class="option">-N</span></samp><dt><samp><span class="option">--forward</span></samp><dd>Ignore patches that <samp><span class="command">patch</span></samp> thinks are reversed or already applied. 
See also <samp><span class="option">-R</span></samp>.  See <a href="#Reversed-Patches">Reversed Patches</a>.

     <br><dt><samp><span class="option">--no-backup-if-mismatch</span></samp><dd>Do not back up the original contents of files.  This is the default
behavior when conforming to <span class="sc">posix</span>.  See <a href="#Backups">Backups</a>.

     <br><dt><samp><span class="option">-o </span><var>file</var></samp><dt><samp><span class="option">--output=</span><var>file</var></samp><dd>Use <var>file</var> as the output file name.  See <a href="#patch-Options">patch Options</a>.

     <br><dt><samp><span class="option">-p</span><var>number</var></samp><dt><samp><span class="option">--strip=</span><var>number</var></samp><dd>Set the file name strip count to <var>number</var>.  See <a href="#patch-Directories">patch Directories</a>.

     <br><dt><samp><span class="option">--posix</span></samp><dd>Conform to <span class="sc">posix</span>, as if the <samp><span class="env">POSIXLY_CORRECT</span></samp> environment
variable had been set.  See <a href="#patch-and-POSIX">patch and POSIX</a>.

     <br><dt><samp><span class="option">--quoting-style=</span><var>word</var></samp><dd>Use style <var>word</var> to quote names in diagnostics, as if the
<samp><span class="env">QUOTING_STYLE</span></samp> environment variable had been set to <var>word</var>. 
See <a href="#patch-Quoting-Style">patch Quoting Style</a>.

     <br><dt><samp><span class="option">-r </span><var>reject-file</var></samp><dt><samp><span class="option">--reject-file=</span><var>reject-file</var></samp><dd>Use <var>reject-file</var> as the reject file name.  See <a href="#Reject-Names">Reject Names</a>.

     <br><dt><samp><span class="option">-R</span></samp><dt><samp><span class="option">--reverse</span></samp><dd>Assume that this patch was created with the old and new files swapped. 
See <a href="#Reversed-Patches">Reversed Patches</a>.

     <br><dt><samp><span class="option">-s</span></samp><dt><samp><span class="option">--quiet</span></samp><dt><samp><span class="option">--silent</span></samp><dd>Work silently unless an error occurs.  See <a href="#patch-Messages">patch Messages</a>.

     <br><dt><samp><span class="option">-t</span></samp><dt><samp><span class="option">--batch</span></samp><dd>Do not ask any questions.  See <a href="#patch-Messages">patch Messages</a>.

     <br><dt><samp><span class="option">-T</span></samp><dt><samp><span class="option">--set-time</span></samp><dd>Set the modification and access times of patched files from time
stamps given in context diff headers, assuming that the context diff
headers use local time.  See <a href="#Patching-Time-Stamps">Patching Time Stamps</a>.

     <br><dt><samp><span class="option">-u</span></samp><dt><samp><span class="option">--unified</span></samp><dd>Interpret the patch file as a unified diff.  See <a href="#patch-Input">patch Input</a>.

     <br><dt><samp><span class="option">-v</span></samp><dt><samp><span class="option">--version</span></samp><dd>Output version information and then exit.

     <br><dt><samp><span class="option">-V </span><var>backup-style</var></samp><dt><samp><span class="option">--version=control=</span><var>backup-style</var></samp><dd>Select the naming convention for backup file names.  See <a href="#Backup-Names">Backup Names</a>.

     <br><dt><samp><span class="option">--verbose</span></samp><dd>Print more diagnostics than usual.  See <a href="#patch-Messages">patch Messages</a>.

     <br><dt><samp><span class="option">-x </span><var>number</var></samp><dt><samp><span class="option">--debug=</span><var>number</var></samp><dd>Set internal debugging flags.  Of interest only to <samp><span class="command">patch</span></samp>
patchers.

     <br><dt><samp><span class="option">-Y </span><var>prefix</var></samp><dt><samp><span class="option">--basename-prefix=</span><var>prefix</var></samp><dd>Prepend <var>prefix</var> to base names of backup files.  See <a href="#Backup-Names">Backup Names</a>.

     <br><dt><samp><span class="option">-z </span><var>suffix</var></samp><dt><samp><span class="option">--suffix=</span><var>suffix</var></samp><dd>Use <var>suffix</var> as the backup extension instead of `<samp><span class="samp">.orig</span></samp>' or
`<samp><span class="samp">~</span></samp>'.  See <a href="#Backup-Names">Backup Names</a>.

     <br><dt><samp><span class="option">-Z</span></samp><dt><samp><span class="option">--set-utc</span></samp><dd>Set the modification and access times of patched files from time
stamps given in context diff headers, assuming that the context diff
headers use <span class="sc">utc</span>.  See <a href="#Patching-Time-Stamps">Patching Time Stamps</a>.

   </dl>

<div class="node">
<p><hr>
<a name="Invoking-sdiff"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Standards-conformance">Standards conformance</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Invoking-patch">Invoking patch</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Top">Top</a>

</div>

<h2 class="chapter">16 Invoking <samp><span class="command">sdiff</span></samp></h2>

<p><a name="index-invoking-_0040command_007bsdiff_007d-155"></a><a name="index-g_t_0040command_007bsdiff_007d-invocation-156"></a>
The <samp><span class="command">sdiff</span></samp> command merges two files and interactively outputs the
results.  Its arguments are as follows:

<pre class="example">     sdiff -o <var>outfile</var> <var>options</var>... <var>from-file</var> <var>to-file</var>
</pre>
   <p>This merges <var>from-file</var> with <var>to-file</var>, with output to <var>outfile</var>. 
If <var>from-file</var> is a directory and <var>to-file</var> is not, <samp><span class="command">sdiff</span></samp>
compares the file in <var>from-file</var> whose file name is that of <var>to-file</var>,
and vice versa.  <var>from-file</var> and <var>to-file</var> may not both be
directories.

   <p><samp><span class="command">sdiff</span></samp> options begin with `<samp><span class="samp">-</span></samp>', so normally <var>from-file</var>
and <var>to-file</var> may not begin with `<samp><span class="samp">-</span></samp>'.  However, <samp><span class="option">--</span></samp> as an
argument by itself treats the remaining arguments as file names even if
they begin with `<samp><span class="samp">-</span></samp>'.  You may not use <samp><span class="file">-</span></samp> as an input file.

   <p><samp><span class="command">sdiff</span></samp> without <samp><span class="option">-o</span></samp> (or <samp><span class="option">--output</span></samp>) produces a
side-by-side difference.  This usage is obsolete; use the <samp><span class="option">-y</span></samp>
or <samp><span class="option">--side-by-side</span></samp> option of <samp><span class="command">diff</span></samp> instead.

   <p>An exit status of 0 means no differences were found, 1 means some
differences were found, and 2 means trouble.

<ul class="menu">
<li><a accesskey="1" href="#sdiff-Options">sdiff Options</a>:  Summary of options to <samp><span class="command">diff</span></samp>. 
</ul>

<div class="node">
<p><hr>
<a name="sdiff-Options"></a>
Up:&nbsp;<a rel="up" accesskey="u" href="#Invoking-sdiff">Invoking sdiff</a>

</div>

<h3 class="section">16.1 Options to <samp><span class="command">sdiff</span></samp></h3>

<p><a name="index-g_t_0040command_007bsdiff_007d-options-157"></a><a name="index-options-for-_0040command_007bsdiff_007d-158"></a>
Below is a summary of all of the options that <span class="sc">gnu</span> <samp><span class="command">sdiff</span></samp> accepts. 
Each option has two equivalent names, one of which is a single
letter preceded by `<samp><span class="samp">-</span></samp>', and the other of which is a long name
preceded by `<samp><span class="samp">--</span></samp>'.  Multiple single letter options (unless they take
an argument) can be combined into a single command line argument.  Long
named options can be abbreviated to any unique prefix of their name.

     <dl>
<dt><samp><span class="option">-a</span></samp><dt><samp><span class="option">--text</span></samp><dd>Treat all files as text and compare them line-by-line, even if they
do not appear to be text.  See <a href="#Binary">Binary</a>.

     <br><dt><samp><span class="option">-b</span></samp><dt><samp><span class="option">--ignore-space-change</span></samp><dd>Ignore changes in amount of white space.  See <a href="#White-Space">White Space</a>.

     <br><dt><samp><span class="option">-B</span></samp><dt><samp><span class="option">--ignore-blank-lines</span></samp><dd>Ignore changes that just insert or delete blank lines.  See <a href="#Blank-Lines">Blank Lines</a>.

     <br><dt><samp><span class="option">-d</span></samp><dt><samp><span class="option">--minimal</span></samp><dd>Change the algorithm to perhaps find a smaller set of changes.  This
makes <samp><span class="command">sdiff</span></samp> slower (sometimes much slower).  See <a href="#diff-Performance">diff Performance</a>.

     <br><dt><samp><span class="option">--diff-program=</span><var>program</var></samp><dd>Use the compatible comparison program <var>program</var> to compare files
instead of <samp><span class="command">diff</span></samp>.

     <br><dt><samp><span class="option">-E</span></samp><dt><samp><span class="option">--ignore-tab-expansion</span></samp><dd>Ignore changes due to tab expansion. 
See <a href="#White-Space">White Space</a>.

     <br><dt><samp><span class="option">--help</span></samp><dd>Output a summary of usage and then exit.

     <br><dt><samp><span class="option">-i</span></samp><dt><samp><span class="option">--ignore-case</span></samp><dd>Ignore changes in case; consider upper- and lower-case to be the same. 
See <a href="#Case-Folding">Case Folding</a>.

     <br><dt><samp><span class="option">-I </span><var>regexp</var></samp><dt><samp><span class="option">--ignore-matching-lines=</span><var>regexp</var></samp><dd>Ignore changes that just insert or delete lines that match <var>regexp</var>. 
See <a href="#Specified-Folding">Specified Folding</a>.

     <br><dt><samp><span class="option">-l</span></samp><dt><samp><span class="option">--left-column</span></samp><dd>Print only the left column of two common lines. 
See <a href="#Side-by-Side-Format">Side by Side Format</a>.

     <br><dt><samp><span class="option">-o </span><var>file</var></samp><dt><samp><span class="option">--output=</span><var>file</var></samp><dd>Put merged output into <var>file</var>.  This option is required for merging.

     <br><dt><samp><span class="option">-s</span></samp><dt><samp><span class="option">--suppress-common-lines</span></samp><dd>Do not print common lines.  See <a href="#Side-by-Side-Format">Side by Side Format</a>.

     <br><dt><samp><span class="option">--speed-large-files</span></samp><dd>Use heuristics to speed handling of large files that have numerous
scattered small changes.  See <a href="#diff-Performance">diff Performance</a>.

     <br><dt><samp><span class="option">--strip-trailing-cr</span></samp><dd>Strip any trailing carriage return at the end of an input line. 
See <a href="#Binary">Binary</a>.

     <br><dt><samp><span class="option">-t</span></samp><dt><samp><span class="option">--expand-tabs</span></samp><dd>Expand tabs to spaces in the output, to preserve the alignment of tabs
in the input files.  See <a href="#Tabs">Tabs</a>.

     <br><dt><samp><span class="option">-v</span></samp><dt><samp><span class="option">--version</span></samp><dd>Output version information and then exit.

     <br><dt><samp><span class="option">-w </span><var>columns</var></samp><dt><samp><span class="option">--width=</span><var>columns</var></samp><dd>Output at most <var>columns</var> (default 130) print columns per line. 
See <a href="#Side-by-Side-Format">Side by Side Format</a>.  Note that for historical reasons, this
option is <samp><span class="option">-W</span></samp> in <samp><span class="command">diff</span></samp>, <samp><span class="option">-w</span></samp> in <samp><span class="command">sdiff</span></samp>.

     <br><dt><samp><span class="option">-W</span></samp><dt><samp><span class="option">--ignore-all-space</span></samp><dd>Ignore white space when comparing lines.  See <a href="#White-Space">White Space</a>. 
Note that for historical reasons, this option is <samp><span class="option">-w</span></samp> in <samp><span class="command">diff</span></samp>,
<samp><span class="option">-W</span></samp> in <samp><span class="command">sdiff</span></samp>. 
</dl>

<div class="node">
<p><hr>
<a name="Standards-conformance"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Projects">Projects</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Invoking-sdiff">Invoking sdiff</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Top">Top</a>

</div>

<h2 class="chapter">17 Standards conformance</h2>

<p><a name="index-g_t_0040sc_007bposix_007d-159"></a>
<a name="index-POSIXLY_005fCORRECT-160"></a>In a few cases, the <span class="sc">gnu</span> utilities' default behavior is
incompatible with the <span class="sc">posix</span> standard.  To suppress these
incompatibilities, define the <samp><span class="env">POSIXLY_CORRECT</span></samp> environment
variable.  Unless you are checking for <span class="sc">posix</span> conformance, you
probably do not need to define <samp><span class="env">POSIXLY_CORRECT</span></samp>.

   <p>Normally options and operands can appear in any order, and programs act
as if all the options appear before any operands.  For example,
`<samp><span class="samp">diff lao tzu -C 2</span></samp>' acts like `<samp><span class="samp">diff -C 2 lao tzu</span></samp>', since
`<samp><span class="samp">2</span></samp>' is an option-argument of <samp><span class="option">-C</span></samp>.  However, if the
<samp><span class="env">POSIXLY_CORRECT</span></samp> environment variable is set, options must appear
before operands, unless otherwise specified for a particular command.

   <p>Newer versions of <span class="sc">posix</span> are occasionally incompatible with older
versions.  For example, older versions of <span class="sc">posix</span> allowed the
command `<samp><span class="samp">diff -c -10</span></samp>' to have the same meaning as `<samp><span class="samp">diff -C
10</span></samp>', but <span class="sc">posix</span> 1003.1-2001 `<samp><span class="samp">diff</span></samp>' no longer allows
digit-string options like <samp><span class="option">-10</span></samp>.

   <p><a name="index-g_t_005fPOSIX2_005fVERSION-161"></a>The <span class="sc">gnu</span> utilities normally conform to the version of <span class="sc">posix</span>
that is standard for your system.  To cause them to conform to a
different version of <span class="sc">posix</span>, define the <samp><span class="env">_POSIX2_VERSION</span></samp>
environment variable to a value of the form <var>yyyymm</var> specifying
the year and month the standard was adopted.  Two values are currently
supported for <samp><span class="env">_POSIX2_VERSION</span></samp>: `<samp><span class="samp">199209</span></samp>' stands for
<span class="sc">posix</span> 1003.2-1992, and `<samp><span class="samp">200112</span></samp>' stands for <span class="sc">posix</span>
1003.1-2001.  For example, if you are running older software that
assumes an older version of <span class="sc">posix</span> and uses `<samp><span class="samp">diff -c -10</span></samp>',
you can work around the compatibility problems by setting
`<samp><span class="samp">_POSIX2_VERSION=199209</span></samp>' in your environment.

<div class="node">
<p><hr>
<a name="Projects"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Copying-This-Manual">Copying This Manual</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Standards-conformance">Standards conformance</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Top">Top</a>

</div>

<h2 class="chapter">18 Future Projects</h2>

<p>Here are some ideas for improving <span class="sc">gnu</span> <samp><span class="command">diff</span></samp> and
<samp><span class="command">patch</span></samp>.  The <span class="sc">gnu</span> project has identified some
improvements as potential programming projects for volunteers.  You
can also help by reporting any bugs that you find.

   <p>If you are a programmer and would like to contribute something to the
<span class="sc">gnu</span> project, please consider volunteering for one of these
projects.  If you are seriously contemplating work, please write to
<a href="mailto:gnu@gnu.org">gnu@gnu.org</a> to coordinate with other volunteers.

<ul class="menu">
<li><a accesskey="1" href="#Shortcomings">Shortcomings</a>:  Suggested projects for improvements. 
<li><a accesskey="2" href="#Bugs">Bugs</a>:          Reporting bugs. 
</ul>

<div class="node">
<p><hr>
<a name="Shortcomings"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Bugs">Bugs</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Projects">Projects</a>

</div>

<h3 class="section">18.1 Suggested Projects for Improving <span class="sc">gnu</span> <samp><span class="command">diff</span></samp> and <samp><span class="command">patch</span></samp></h3>

<p><a name="index-projects-for-directories-162"></a>
One should be able to use <span class="sc">gnu</span> <samp><span class="command">diff</span></samp> to generate a patch from any
pair of directory trees, and given the patch and a copy of one such
tree, use <samp><span class="command">patch</span></samp> to generate a faithful copy of the other. 
Unfortunately, some changes to directory trees cannot be expressed using
current patch formats; also, <samp><span class="command">patch</span></samp> does not handle some of the
existing formats.  These shortcomings motivate the following suggested
projects.

<ul class="menu">
<li><a accesskey="1" href="#Internationalization">Internationalization</a>:  Handling multibyte and varying-width characters. 
<li><a accesskey="2" href="#Changing-Structure">Changing Structure</a>:    Handling changes to the directory structure. 
<li><a accesskey="3" href="#Special-Files">Special Files</a>:         Handling symbolic links, device special files, etc. 
<li><a accesskey="4" href="#Unusual-File-Names">Unusual File Names</a>:    Handling file names that contain unusual characters. 
<li><a accesskey="5" href="#Time-Stamp-Order">Time Stamp Order</a>:      Outputting diffs in time stamp order. 
<li><a accesskey="6" href="#Ignoring-Changes">Ignoring Changes</a>:      Ignoring certain changes while showing others. 
<li><a accesskey="7" href="#Speedups">Speedups</a>:              Improving performance. 
</ul>

<div class="node">
<p><hr>
<a name="Internationalization"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Changing-Structure">Changing Structure</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Shortcomings">Shortcomings</a>

</div>

<h4 class="subsection">18.1.1 Handling Multibyte and Varying-Width Characters</h4>

<p><a name="index-multibyte-characters-163"></a><a name="index-varying_002dwidth-characters-164"></a>
<samp><span class="command">diff</span></samp>, <samp><span class="command">diff3</span></samp> and <samp><span class="command">sdiff</span></samp> treat each line of
input as a string of unibyte characters.  This can mishandle multibyte
characters in some cases.  For example, when asked to ignore spaces,
<samp><span class="command">diff</span></samp> does not properly ignore a multibyte space character.

   <p>Also, <samp><span class="command">diff</span></samp> currently assumes that each byte is one column
wide, and this assumption is incorrect in some locales, e.g., locales
that use UTF-8 encoding.  This causes problems with the <samp><span class="option">-y</span></samp> or
<samp><span class="option">--side-by-side</span></samp> option of <samp><span class="command">diff</span></samp>.

   <p>These problems need to be fixed without unduly affecting the
performance of the utilities in unibyte environments.

   <p>The IBM GNU/Linux Technology Center Internationalization Team has
proposed some patches to support internationalized <samp><span class="command">diff</span></samp>
<a href="http://oss.software.ibm.com/developer/opensource/linux/patches/i18n/diffutils-2.7.2-i18n-0.1.patch.gz">http://oss.software.ibm.com/developer/opensource/linux/patches/i18n/diffutils-2.7.2-i18n-0.1.patch.gz</a>. 
Unfortunately, these patches are incomplete and are to an older
version of <samp><span class="command">diff</span></samp>, so more work needs to be done in this area.

<div class="node">
<p><hr>
<a name="Changing-Structure"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Special-Files">Special Files</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Internationalization">Internationalization</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Shortcomings">Shortcomings</a>

</div>

<h4 class="subsection">18.1.2 Handling Changes to the Directory Structure</h4>

<p><a name="index-directory-structure-changes-165"></a>
<samp><span class="command">diff</span></samp> and <samp><span class="command">patch</span></samp> do not handle some changes to directory
structure.  For example, suppose one directory tree contains a directory
named `<samp><span class="samp">D</span></samp>' with some subsidiary files, and another contains a file
with the same name `<samp><span class="samp">D</span></samp>'.  `<samp><span class="samp">diff -r</span></samp>' does not output enough
information for <samp><span class="command">patch</span></samp> to transform the directory subtree into
the file.

   <p>There should be a way to specify that a file has been removed without
having to include its entire contents in the patch file.  There should
also be a way to tell <samp><span class="command">patch</span></samp> that a file was renamed, even if
there is no way for <samp><span class="command">diff</span></samp> to generate such information. 
There should be a way to tell <samp><span class="command">patch</span></samp> that a file's time stamp
has changed, even if its contents have not changed.

   <p>These problems can be fixed by extending the <samp><span class="command">diff</span></samp> output format
to represent changes in directory structure, and extending <samp><span class="command">patch</span></samp>
to understand these extensions.

<div class="node">
<p><hr>
<a name="Special-Files"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Unusual-File-Names">Unusual File Names</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Changing-Structure">Changing Structure</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Shortcomings">Shortcomings</a>

</div>

<h4 class="subsection">18.1.3 Files that are Neither Directories Nor Regular Files</h4>

<p><a name="index-special-files-166"></a>
Some files are neither directories nor regular files: they are unusual
files like symbolic links, device special files, named pipes, and
sockets.  Currently, <samp><span class="command">diff</span></samp> treats symbolic links like regular files;
it treats other special files like regular files if they are specified
at the top level, but simply reports their presence when comparing
directories.  This means that <samp><span class="command">patch</span></samp> cannot represent changes
to such files.  For example, if you change which file a symbolic link
points to, <samp><span class="command">diff</span></samp> outputs the difference between the two files,
instead of the change to the symbolic link.

<!-- This might not be a good idea; is it wise for root to install devices -->
<!-- this way? -->
<p><samp><span class="command">diff</span></samp> should optionally report changes to special files specially,
and <samp><span class="command">patch</span></samp> should be extended to understand these extensions.

<div class="node">
<p><hr>
<a name="Unusual-File-Names"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Time-Stamp-Order">Time Stamp Order</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Special-Files">Special Files</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Shortcomings">Shortcomings</a>

</div>

<h4 class="subsection">18.1.4 File Names that Contain Unusual Characters</h4>

<p><a name="index-file-names-with-unusual-characters-167"></a>
When a file name contains an unusual character like a newline or
white space, `<samp><span class="samp">diff -r</span></samp>' generates a patch that <samp><span class="command">patch</span></samp> cannot
parse.  The problem is with format of <samp><span class="command">diff</span></samp> output, not just with
<samp><span class="command">patch</span></samp>, because with odd enough file names one can cause
<samp><span class="command">diff</span></samp> to generate a patch that is syntactically correct but
patches the wrong files.  The format of <samp><span class="command">diff</span></samp> output should be
extended to handle all possible file names.

<div class="node">
<p><hr>
<a name="Time-Stamp-Order"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Ignoring-Changes">Ignoring Changes</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Unusual-File-Names">Unusual File Names</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Shortcomings">Shortcomings</a>

</div>

<h4 class="subsection">18.1.5 Outputting Diffs in Time Stamp Order</h4>

<p>Applying <samp><span class="command">patch</span></samp> to a multiple-file diff can result in files
whose time stamps are out of order.  <span class="sc">gnu</span> <samp><span class="command">patch</span></samp> has
options to restore the time stamps of the updated files
(see <a href="#Patching-Time-Stamps">Patching Time Stamps</a>), but sometimes it is useful to generate
a patch that works even if the recipient does not have <span class="sc">gnu</span> patch,
or does not use these options.  One way to do this would be to
implement a <samp><span class="command">diff</span></samp> option to output diffs in time stamp order.

<div class="node">
<p><hr>
<a name="Ignoring-Changes"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Speedups">Speedups</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Time-Stamp-Order">Time Stamp Order</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Shortcomings">Shortcomings</a>

</div>

<h4 class="subsection">18.1.6 Ignoring Certain Changes</h4>

<p>It would be nice to have a feature for specifying two strings, one in
<var>from-file</var> and one in <var>to-file</var>, which should be considered to
match.  Thus, if the two strings are `<samp><span class="samp">foo</span></samp>' and `<samp><span class="samp">bar</span></samp>', then if
two lines differ only in that `<samp><span class="samp">foo</span></samp>' in file 1 corresponds to
`<samp><span class="samp">bar</span></samp>' in file 2, the lines are treated as identical.

   <p>It is not clear how general this feature can or should be, or
what syntax should be used for it.

   <p>A partial substitute is to filter one or both files before comparing,
e.g.:

<pre class="example">     sed 's/foo/bar/g' file1 | diff - file2
</pre>
   <p>However, this outputs the filtered text, not the original.

<div class="node">
<p><hr>
<a name="Speedups"></a>
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Ignoring-Changes">Ignoring Changes</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Shortcomings">Shortcomings</a>

</div>

<h4 class="subsection">18.1.7 Improving Performance</h4>

<p>When comparing two large directory structures, one of which was
originally copied from the other with time stamps preserved (e.g.,
with `<samp><span class="samp">cp -pR</span></samp>'), it would greatly improve performance if an option
told <samp><span class="command">diff</span></samp> to assume that two files with the same size and
time stamps have the same content.  See <a href="#diff-Performance">diff Performance</a>.

<div class="node">
<p><hr>
<a name="Bugs"></a>
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Shortcomings">Shortcomings</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Projects">Projects</a>

</div>

<h3 class="section">18.2 Reporting Bugs</h3>

<p><a name="index-bug-reports-168"></a><a name="index-reporting-bugs-169"></a>
If you think you have found a bug in <span class="sc">gnu</span> <samp><span class="command">cmp</span></samp>,
<samp><span class="command">diff</span></samp>, <samp><span class="command">diff3</span></samp>, or <samp><span class="command">sdiff</span></samp>, please report it
by electronic mail to the
<a href="http://mail.gnu.org/mailman/listinfo/bug-gnu-utils">GNU utilities bug report mailing list</a> <a href="mailto:bug-gnu-utils@gnu.org">bug-gnu-utils@gnu.org</a>.  Please send
bug reports for <span class="sc">gnu</span> <samp><span class="command">patch</span></samp> to
<a href="mailto:bug-patch@gnu.org">bug-patch@gnu.org</a>.  Send as precise a description of the
problem as you can, including the output of the <samp><span class="option">--version</span></samp>
option and sample input files that produce the bug, if applicable.  If
you have a nontrivial fix for the bug, please send it as well.  If you
have a patch, please send it too.  It may simplify the maintainer's
job if the patch is relative to a recent test release, which you can
find in the directory <a href="ftp://alpha.gnu.org/gnu/diffutils/">ftp://alpha.gnu.org/gnu/diffutils/</a>.

<div class="node">
<p><hr>
<a name="Copying-This-Manual"></a>
Next:&nbsp;<a rel="next" accesskey="n" href="#Index">Index</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Projects">Projects</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Top">Top</a>

</div>

<h2 class="appendix">Appendix A Copying This Manual</h2>

<ul class="menu">
<li><a accesskey="1" href="#GNU-Free-Documentation-License">GNU Free Documentation License</a>:   License for copying this manual. 
</ul>

<div class="node">
<p><hr>
<a name="GNU-Free-Documentation-License"></a>
Up:&nbsp;<a rel="up" accesskey="u" href="#Copying-This-Manual">Copying This Manual</a>

</div>

<h3 class="appendixsec">A.1 GNU Free Documentation License</h3>

<p><a name="index-FDL_002c-GNU-Free-Documentation-License-170"></a><div align="center">Version 1.1, March 2000</div>

<pre class="display">     Copyright &copy; 2000 Free Software Foundation, Inc.
     59 Temple Place, Suite 330, Boston, MA  02111-1307, USA
     
     Everyone is permitted to copy and distribute verbatim copies
     of this license document, but changing it is not allowed.
</pre>
     <ol type=1 start=0>
<li>PREAMBLE

     <p>The purpose of this License is to make a manual, textbook, or other
written document <dfn>free</dfn> in the sense of freedom: to assure everyone
the effective freedom to copy and redistribute it, with or without
modifying it, either commercially or noncommercially.  Secondarily,
this License preserves for the author and publisher a way to get
credit for their work, while not being considered responsible for
modifications made by others.

     <p>This License is a kind of &ldquo;copyleft&rdquo;, which means that derivative
works of the document must themselves be free in the same sense.  It
complements the GNU General Public License, which is a copyleft
license designed for free software.

     <p>We have designed this License in order to use it for manuals for free
software, because free software needs free documentation: a free
program should come with manuals providing the same freedoms that the
software does.  But this License is not limited to software manuals;
it can be used for any textual work, regardless of subject matter or
whether it is published as a printed book.  We recommend this License
principally for works whose purpose is instruction or reference.

     <li>APPLICABILITY AND DEFINITIONS

     <p>This License applies to any manual or other work that contains a
notice placed by the copyright holder saying it can be distributed
under the terms of this License.  The &ldquo;Document&rdquo;, below, refers to any
such manual or work.  Any member of the public is a licensee, and is
addressed as &ldquo;you&rdquo;.

     <p>A &ldquo;Modified Version&rdquo; of the Document means any work containing the
Document or a portion of it, either copied verbatim, or with
modifications and/or translated into another language.

     <p>A &ldquo;Secondary Section&rdquo; is a named appendix or a front-matter section of
the Document that deals exclusively with the relationship of the
publishers or authors of the Document to the Document's overall subject
(or to related matters) and contains nothing that could fall directly
within that overall subject.  (For example, if the Document is in part a
textbook of mathematics, a Secondary Section may not explain any
mathematics.)  The relationship could be a matter of historical
connection with the subject or with related matters, or of legal,
commercial, philosophical, ethical or political position regarding
them.

     <p>The &ldquo;Invariant Sections&rdquo; are certain Secondary Sections whose titles
are designated, as being those of Invariant Sections, in the notice
that says that the Document is released under this License.

     <p>The &ldquo;Cover Texts&rdquo; are certain short passages of text that are listed,
as Front-Cover Texts or Back-Cover Texts, in the notice that says that
the Document is released under this License.

     <p>A &ldquo;Transparent&rdquo; copy of the Document means a machine-readable copy,
represented in a format whose specification is available to the
general public, whose contents can be viewed and edited directly and
straightforwardly with generic text editors or (for images composed of
pixels) generic paint programs or (for drawings) some widely available
drawing editor, and that is suitable for input to text formatters or
for automatic translation to a variety of formats suitable for input
to text formatters.  A copy made in an otherwise Transparent file
format whose markup has been designed to thwart or discourage
subsequent modification by readers is not Transparent.  A copy that is
not &ldquo;Transparent&rdquo; is called &ldquo;Opaque&rdquo;.

     <p>Examples of suitable formats for Transparent copies include plain
<span class="sc">ascii</span> without markup, Texinfo input format, LaTeX input format,
<acronym>SGML</acronym> or <acronym>XML</acronym> using a publicly available
<acronym>DTD</acronym>, and standard-conforming simple <acronym>HTML</acronym> designed
for human modification.  Opaque formats include PostScript,
<acronym>PDF</acronym>, proprietary formats that can be read and edited only by
proprietary word processors, <acronym>SGML</acronym> or <acronym>XML</acronym> for which
the <acronym>DTD</acronym> and/or processing tools are not generally available,
and the machine-generated <acronym>HTML</acronym> produced by some word
processors for output purposes only.

     <p>The &ldquo;Title Page&rdquo; means, for a printed book, the title page itself,
plus such following pages as are needed to hold, legibly, the material
this License requires to appear in the title page.  For works in
formats which do not have any title page as such, &ldquo;Title Page&rdquo; means
the text near the most prominent appearance of the work's title,
preceding the beginning of the body of the text.

     <li>VERBATIM COPYING

     <p>You may copy and distribute the Document in any medium, either
commercially or noncommercially, provided that this License, the
copyright notices, and the license notice saying this License applies
to the Document are reproduced in all copies, and that you add no other
conditions whatsoever to those of this License.  You may not use
technical measures to obstruct or control the reading or further
copying of the copies you make or distribute.  However, you may accept
compensation in exchange for copies.  If you distribute a large enough
number of copies you must also follow the conditions in section 3.

     <p>You may also lend copies, under the same conditions stated above, and
you may publicly display copies.

     <li>COPYING IN QUANTITY

     <p>If you publish printed copies of the Document numbering more than 100,
and the Document's license notice requires Cover Texts, you must enclose
the copies in covers that carry, clearly and legibly, all these Cover
Texts: Front-Cover Texts on the front cover, and Back-Cover Texts on
the back cover.  Both covers must also clearly and legibly identify
you as the publisher of these copies.  The front cover must present
the full title with all words of the title equally prominent and
visible.  You may add other material on the covers in addition. 
Copying with changes limited to the covers, as long as they preserve
the title of the Document and satisfy these conditions, can be treated
as verbatim copying in other respects.

     <p>If the required texts for either cover are too voluminous to fit
legibly, you should put the first ones listed (as many as fit
reasonably) on the actual cover, and continue the rest onto adjacent
pages.

     <p>If you publish or distribute Opaque copies of the Document numbering
more than 100, you must either include a machine-readable Transparent
copy along with each Opaque copy, or state in or with each Opaque copy
a publicly-accessible computer-network location containing a complete
Transparent copy of the Document, free of added material, which the
general network-using public has access to download anonymously at no
charge using public-standard network protocols.  If you use the latter
option, you must take reasonably prudent steps, when you begin
distribution of Opaque copies in quantity, to ensure that this
Transparent copy will remain thus accessible at the stated location
until at least one year after the last time you distribute an Opaque
copy (directly or through your agents or retailers) of that edition to
the public.

     <p>It is requested, but not required, that you contact the authors of the
Document well before redistributing any large number of copies, to give
them a chance to provide you with an updated version of the Document.

     <li>MODIFICATIONS

     <p>You may copy and distribute a Modified Version of the Document under
the conditions of sections 2 and 3 above, provided that you release
the Modified Version under precisely this License, with the Modified
Version filling the role of the Document, thus licensing distribution
and modification of the Modified Version to whoever possesses a copy
of it.  In addition, you must do these things in the Modified Version:

          <ol type=A start=1>
<li>Use in the Title Page (and on the covers, if any) a title distinct
from that of the Document, and from those of previous versions
(which should, if there were any, be listed in the History section
of the Document).  You may use the same title as a previous version
if the original publisher of that version gives permission.

          <li>List on the Title Page, as authors, one or more persons or entities
responsible for authorship of the modifications in the Modified
Version, together with at least five of the principal authors of the
Document (all of its principal authors, if it has less than five).

          <li>State on the Title page the name of the publisher of the
Modified Version, as the publisher.

          <li>Preserve all the copyright notices of the Document.

          <li>Add an appropriate copyright notice for your modifications
adjacent to the other copyright notices.

          <li>Include, immediately after the copyright notices, a license notice
giving the public permission to use the Modified Version under the
terms of this License, in the form shown in the Addendum below.

          <li>Preserve in that license notice the full lists of Invariant Sections
and required Cover Texts given in the Document's license notice.

          <li>Include an unaltered copy of this License.

          <li>Preserve the section entitled &ldquo;History&rdquo;, and its title, and add to
it an item stating at least the title, year, new authors, and
publisher of the Modified Version as given on the Title Page.  If
there is no section entitled &ldquo;History&rdquo; in the Document, create one
stating the title, year, authors, and publisher of the Document as
given on its Title Page, then add an item describing the Modified
Version as stated in the previous sentence.

          <li>Preserve the network location, if any, given in the Document for
public access to a Transparent copy of the Document, and likewise
the network locations given in the Document for previous versions
it was based on.  These may be placed in the &ldquo;History&rdquo; section. 
You may omit a network location for a work that was published at
least four years before the Document itself, or if the original
publisher of the version it refers to gives permission.

          <li>In any section entitled &ldquo;Acknowledgments&rdquo; or &ldquo;Dedications&rdquo;,
preserve the section's title, and preserve in the section all the
substance and tone of each of the contributor acknowledgments
and/or dedications given therein.

          <li>Preserve all the Invariant Sections of the Document,
unaltered in their text and in their titles.  Section numbers
or the equivalent are not considered part of the section titles.

          <li>Delete any section entitled &ldquo;Endorsements&rdquo;.  Such a section
may not be included in the Modified Version.

          <li>Do not retitle any existing section as &ldquo;Endorsements&rdquo;
or to conflict in title with any Invariant Section.
          </ol>

     <p>If the Modified Version includes new front-matter sections or
appendices that qualify as Secondary Sections and contain no material
copied from the Document, you may at your option designate some or all
of these sections as invariant.  To do this, add their titles to the
list of Invariant Sections in the Modified Version's license notice. 
These titles must be distinct from any other section titles.

     <p>You may add a section entitled &ldquo;Endorsements&rdquo;, provided it contains
nothing but endorsements of your Modified Version by various
parties&mdash;for example, statements of peer review or that the text has
been approved by an organization as the authoritative definition of a
standard.

     <p>You may add a passage of up to five words as a Front-Cover Text, and a
passage of up to 25 words as a Back-Cover Text, to the end of the list
of Cover Texts in the Modified Version.  Only one passage of
Front-Cover Text and one of Back-Cover Text may be added by (or
through arrangements made by) any one entity.  If the Document already
includes a cover text for the same cover, previously added by you or
by arrangement made by the same entity you are acting on behalf of,
you may not add another; but you may replace the old one, on explicit
permission from the previous publisher that added the old one.

     <p>The author(s) and publisher(s) of the Document do not by this License
give permission to use their names for publicity for or to assert or
imply endorsement of any Modified Version.

     <li>COMBINING DOCUMENTS

     <p>You may combine the Document with other documents released under this
License, under the terms defined in section 4 above for modified
versions, provided that you include in the combination all of the
Invariant Sections of all of the original documents, unmodified, and
list them all as Invariant Sections of your combined work in its
license notice.

     <p>The combined work need only contain one copy of this License, and
multiple identical Invariant Sections may be replaced with a single
copy.  If there are multiple Invariant Sections with the same name but
different contents, make the title of each such section unique by
adding at the end of it, in parentheses, the name of the original
author or publisher of that section if known, or else a unique number. 
Make the same adjustment to the section titles in the list of
Invariant Sections in the license notice of the combined work.

     <p>In the combination, you must combine any sections entitled &ldquo;History&rdquo;
in the various original documents, forming one section entitled
&ldquo;History&rdquo;; likewise combine any sections entitled &ldquo;Acknowledgments&rdquo;,
and any sections entitled &ldquo;Dedications&rdquo;.  You must delete all sections
entitled &ldquo;Endorsements.&rdquo;

     <li>COLLECTIONS OF DOCUMENTS

     <p>You may make a collection consisting of the Document and other documents
released under this License, and replace the individual copies of this
License in the various documents with a single copy that is included in
the collection, provided that you follow the rules of this License for
verbatim copying of each of the documents in all other respects.

     <p>You may extract a single document from such a collection, and distribute
it individually under this License, provided you insert a copy of this
License into the extracted document, and follow this License in all
other respects regarding verbatim copying of that document.

     <li>AGGREGATION WITH INDEPENDENT WORKS

     <p>A compilation of the Document or its derivatives with other separate
and independent documents or works, in or on a volume of a storage or
distribution medium, does not as a whole count as a Modified Version
of the Document, provided no compilation copyright is claimed for the
compilation.  Such a compilation is called an &ldquo;aggregate&rdquo;, and this
License does not apply to the other self-contained works thus compiled
with the Document, on account of their being thus compiled, if they
are not themselves derivative works of the Document.

     <p>If the Cover Text requirement of section 3 is applicable to these
copies of the Document, then if the Document is less than one quarter
of the entire aggregate, the Document's Cover Texts may be placed on
covers that surround only the Document within the aggregate. 
Otherwise they must appear on covers around the whole aggregate.

     <li>TRANSLATION

     <p>Translation is considered a kind of modification, so you may
distribute translations of the Document under the terms of section 4. 
Replacing Invariant Sections with translations requires special
permission from their copyright holders, but you may include
translations of some or all Invariant Sections in addition to the
original versions of these Invariant Sections.  You may include a
translation of this License provided that you also include the
original English version of this License.  In case of a disagreement
between the translation and the original English version of this
License, the original English version will prevail.

     <li>TERMINATION

     <p>You may not copy, modify, sublicense, or distribute the Document except
as expressly provided for under this License.  Any other attempt to
copy, modify, sublicense or distribute the Document is void, and will
automatically terminate your rights under this License.  However,
parties who have received copies, or rights, from you under this
License will not have their licenses terminated so long as such
parties remain in full compliance.

     <li>FUTURE REVISIONS OF THIS LICENSE

     <p>The Free Software Foundation may publish new, revised versions
of the GNU Free Documentation License from time to time.  Such new
versions will be similar in spirit to the present version, but may
differ in detail to address new problems or concerns.  See
<a href="http://www.gnu.org/copyleft/">http://www.gnu.org/copyleft/</a>.

     <p>Each version of the License is given a distinguishing version number. 
If the Document specifies that a particular numbered version of this
License &ldquo;or any later version&rdquo; applies to it, you have the option of
following the terms and conditions either of that specified version or
of any later version that has been published (not as a draft) by the
Free Software Foundation.  If the Document does not specify a version
number of this License, you may choose any version ever published (not
as a draft) by the Free Software Foundation.
        </ol>

<h4 class="appendixsubsec">A.1.1 ADDENDUM: How to use this License for your documents</h4>

<p>To use this License in a document you have written, include a copy of
the License in the document and put the following copyright and
license notices just after the title page:

<pre class="smallexample">       Copyright (C)  <var>year</var>  <var>your name</var>.
       Permission is granted to copy, distribute and/or modify this document
       under the terms of the GNU Free Documentation License, Version 1.1
       or any later version published by the Free Software Foundation;
       with the Invariant Sections being <var>list their titles</var>, with the
       Front-Cover Texts being <var>list</var>, and with the Back-Cover Texts being <var>list</var>.
       A copy of the license is included in the section entitled ``GNU
       Free Documentation License''.
</pre>
   <p>If you have no Invariant Sections, write &ldquo;with no Invariant Sections&rdquo;
instead of saying which ones are invariant.  If you have no
Front-Cover Texts, write &ldquo;no Front-Cover Texts&rdquo; instead of
&ldquo;Front-Cover Texts being <var>list</var>&rdquo;; likewise for Back-Cover Texts.

   <p>If your document contains nontrivial examples of program code, we
recommend releasing these examples in parallel under your choice of
free software license, such as the GNU General Public License,
to permit their use in free software.

<!-- Local Variables: -->
<!-- ispell-local-pdict: "ispell-dict" -->
<!-- End: -->
<div class="node">
<p><hr>
<a name="Index"></a>
Previous:&nbsp;<a rel="previous" accesskey="p" href="#Copying-This-Manual">Copying This Manual</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="#Top">Top</a>

</div>

<h2 class="appendix">Appendix B Index</h2>

<ul class="index-cp" compact>
<li><a href="#index-g_t_0040samp_007b_0021_007d-output-format-20">`<samp><span class="samp">!</span></samp>' output format</a>: <a href="#Context">Context</a></li>
<li><a href="#index-g_t_0040samp_007b_002b_002d_007d-output-format-24">`<samp><span class="samp">+-</span></samp>' output format</a>: <a href="#Unified-Format">Unified Format</a></li>
<li><a href="#index-g_t_0040samp_007b_003c_007d-output-format-18">`<samp><span class="samp">&lt;</span></samp>' output format</a>: <a href="#Normal">Normal</a></li>
<li><a href="#index-g_t_0040samp_007b_003c_003c_003c_003c_003c_003c_003c_007d-for-marking-conflicts-70">`<samp><span class="samp">&lt;&lt;&lt;&lt;&lt;&lt;&lt;</span></samp>' for marking conflicts</a>: <a href="#Marking-Conflicts">Marking Conflicts</a></li>
<li><a href="#index-g_t_005fPOSIX2_005fVERSION-161"><code>_POSIX2_VERSION</code></a>: <a href="#Standards-conformance">Standards conformance</a></li>
<li><a href="#index-aligning-tab-stops-55">aligning tab stops</a>: <a href="#Tabs">Tabs</a></li>
<li><a href="#index-alternate-file-names-32">alternate file names</a>: <a href="#Alternate-Names">Alternate Names</a></li>
<li><a href="#index-backup-file-names-104">backup file names</a>: <a href="#Backup-Names">Backup Names</a></li>
<li><a href="#index-backup-file-strategy-103">backup file strategy</a>: <a href="#Backups">Backups</a></li>
<li><a href="#index-binary-file-diff-11">binary file diff</a>: <a href="#Binary">Binary</a></li>
<li><a href="#index-blank-and-tab-difference-suppression-4">blank and tab difference suppression</a>: <a href="#White-Space">White Space</a></li>
<li><a href="#index-blank-line-difference-suppression-6">blank line difference suppression</a>: <a href="#Blank-Lines">Blank Lines</a></li>
<li><a href="#index-brief-difference-reports-10">brief difference reports</a>: <a href="#Brief">Brief</a></li>
<li><a href="#index-bug-reports-168">bug reports</a>: <a href="#Bugs">Bugs</a></li>
<li><a href="#index-C-function-headings-30">C function headings</a>: <a href="#C-Function-Headings">C Function Headings</a></li>
<li><a href="#index-C-if_002dthen_002delse-output-format-44">C if-then-else output format</a>: <a href="#If_002dthen_002delse">If-then-else</a></li>
<li><a href="#index-case-difference-suppression-7">case difference suppression</a>: <a href="#Case-Folding">Case Folding</a></li>
<li><a href="#index-ClearCase-84">ClearCase</a>: <a href="#Revision-Control">Revision Control</a></li>
<li><a href="#index-g_t_0040command_007bcmp_007d-invocation-126"><samp><span class="command">cmp</span></samp> invocation</a>: <a href="#Invoking-cmp">Invoking cmp</a></li>
<li><a href="#index-g_t_0040command_007bcmp_007d-options-127"><samp><span class="command">cmp</span></samp> options</a>: <a href="#cmp-Options">cmp Options</a></li>
<li><a href="#index-columnar-output-36">columnar output</a>: <a href="#Side-by-Side">Side by Side</a></li>
<li><a href="#index-common-mistakes-with-patches-122">common mistakes with patches</a>: <a href="#Avoiding-Common-Mistakes">Avoiding Common Mistakes</a></li>
<li><a href="#index-comparing-three-files-58">comparing three files</a>: <a href="#Comparing-Three-Files">Comparing Three Files</a></li>
<li><a href="#index-conflict-65">conflict</a>: <a href="#diff3-Merging">diff3 Merging</a></li>
<li><a href="#index-conflict-marking-69">conflict marking</a>: <a href="#Marking-Conflicts">Marking Conflicts</a></li>
<li><a href="#index-context-output-format-19">context output format</a>: <a href="#Context">Context</a></li>
<li><a href="#index-creating-files-95">creating files</a>: <a href="#Creating-and-Removing">Creating and Removing</a></li>
<li><a href="#index-diagnostics-from-_0040command_007bpatch_007d-110">diagnostics from <samp><span class="command">patch</span></samp></a>: <a href="#patch-Messages">patch Messages</a></li>
<li><a href="#index-g_t_0040command_007bdiff_007d-invocation-144"><samp><span class="command">diff</span></samp> invocation</a>: <a href="#Invoking-diff">Invoking diff</a></li>
<li><a href="#index-diff-merging-74">diff merging</a>: <a href="#Interactive-Merging">Interactive Merging</a></li>
<li><a href="#index-g_t_0040command_007bdiff_007d-options-145"><samp><span class="command">diff</span></samp> options</a>: <a href="#diff-Options">diff Options</a></li>
<li><a href="#index-g_t_0040command_007bdiff_007d-sample-input-15"><samp><span class="command">diff</span></samp> sample input</a>: <a href="#Sample-diff-Input">Sample diff Input</a></li>
<li><a href="#index-g_t_0040command_007bdiff3_007d-hunks-63"><samp><span class="command">diff3</span></samp> hunks</a>: <a href="#diff3-Hunks">diff3 Hunks</a></li>
<li><a href="#index-g_t_0040command_007bdiff3_007d-invocation-148"><samp><span class="command">diff3</span></samp> invocation</a>: <a href="#Invoking-diff3">Invoking diff3</a></li>
<li><a href="#index-g_t_0040command_007bdiff3_007d-options-149"><samp><span class="command">diff3</span></samp> options</a>: <a href="#diff3-Options">diff3 Options</a></li>
<li><a href="#index-g_t_0040command_007bdiff3_007d-sample-input-60"><samp><span class="command">diff3</span></samp> sample input</a>: <a href="#Sample-diff3-Input">Sample diff3 Input</a></li>
<li><a href="#index-directories-and-patch-101">directories and patch</a>: <a href="#patch-Directories">patch Directories</a></li>
<li><a href="#index-directory-structure-changes-165">directory structure changes</a>: <a href="#Changing-Structure">Changing Structure</a></li>
<li><a href="#index-dry-runs-for-_0040command_007bpatch_007d-94">dry runs for <samp><span class="command">patch</span></samp></a>: <a href="#Dry-Runs">Dry Runs</a></li>
<li><a href="#index-g_t_0040command_007bed_007d-script-output-format-39"><samp><span class="command">ed</span></samp> script output format</a>: <a href="#ed-Scripts">ed Scripts</a></li>
<li><a href="#index-EDITOR-79"><code>EDITOR</code></a>: <a href="#Merge-Commands">Merge Commands</a></li>
<li><a href="#index-empty-files_002c-removing-96">empty files, removing</a>: <a href="#Creating-and-Removing">Creating and Removing</a></li>
<li><a href="#index-exabyte_002c-definition-of-139">exabyte, definition of</a>: <a href="#cmp-Options">cmp Options</a></li>
<li><a href="#index-exbibyte_002c-definition-of-140">exbibyte, definition of</a>: <a href="#cmp-Options">cmp Options</a></li>
<li><a href="#index-FDL_002c-GNU-Free-Documentation-License-170">FDL, GNU Free Documentation License</a>: <a href="#GNU-Free-Documentation-License">GNU Free Documentation License</a></li>
<li><a href="#index-file-name-alternates-33">file name alternates</a>: <a href="#Alternate-Names">Alternate Names</a></li>
<li><a href="#index-file-names-with-unusual-characters-167">file names with unusual characters</a>: <a href="#Unusual-File-Names">Unusual File Names</a></li>
<li><a href="#index-format-of-_0040command_007bdiff_007d-output-14">format of <samp><span class="command">diff</span></samp> output</a>: <a href="#Output-Formats">Output Formats</a></li>
<li><a href="#index-format-of-_0040command_007bdiff3_007d-output-59">format of <samp><span class="command">diff3</span></samp> output</a>: <a href="#Comparing-Three-Files">Comparing Three Files</a></li>
<li><a href="#index-formats-for-if_002dthen_002delse-line-groups-47">formats for if-then-else line groups</a>: <a href="#Line-Group-Formats">Line Group Formats</a></li>
<li><a href="#index-forward-_0040command_007bed_007d-script-output-format-40">forward <samp><span class="command">ed</span></samp> script output format</a>: <a href="#Forward-ed">Forward ed</a></li>
<li><a href="#index-full-lines-51">full lines</a>: <a href="#Incomplete-Lines">Incomplete Lines</a></li>
<li><a href="#index-function-headings_002c-C-31">function headings, C</a>: <a href="#C-Function-Headings">C Function Headings</a></li>
<li><a href="#index-fuzz-factor-when-patching-92">fuzz factor when patching</a>: <a href="#Inexact">Inexact</a></li>
<li><a href="#index-gibibyte_002c-definition-of-134">gibibyte, definition of</a>: <a href="#cmp-Options">cmp Options</a></li>
<li><a href="#index-gigabyte_002c-definition-of-133">gigabyte, definition of</a>: <a href="#cmp-Options">cmp Options</a></li>
<li><a href="#index-headings-26">headings</a>: <a href="#Sections">Sections</a></li>
<li><a href="#index-hunks-3">hunks</a>: <a href="#Hunks">Hunks</a></li>
<li><a href="#index-hunks-for-_0040command_007bdiff3_007d-62">hunks for <samp><span class="command">diff3</span></samp></a>: <a href="#diff3-Hunks">diff3 Hunks</a></li>
<li><a href="#index-if_002dthen_002delse-output-format-43">if-then-else output format</a>: <a href="#If_002dthen_002delse">If-then-else</a></li>
<li><a href="#index-g_t_0040command_007bifdef_007d-output-format-45"><samp><span class="command">ifdef</span></samp> output format</a>: <a href="#If_002dthen_002delse">If-then-else</a></li>
<li><a href="#index-imperfect-patch-application-88">imperfect patch application</a>: <a href="#Imperfect">Imperfect</a></li>
<li><a href="#index-incomplete-line-merging-72">incomplete line merging</a>: <a href="#Merging-Incomplete-Lines">Merging Incomplete Lines</a></li>
<li><a href="#index-incomplete-lines-50">incomplete lines</a>: <a href="#Incomplete-Lines">Incomplete Lines</a></li>
<li><a href="#index-inexact-patches-91">inexact patches</a>: <a href="#Inexact">Inexact</a></li>
<li><a href="#index-inhibit-messages-from-_0040command_007bpatch_007d-113">inhibit messages from <samp><span class="command">patch</span></samp></a>: <a href="#More-or-Fewer-Messages">More or Fewer Messages</a></li>
<li><a href="#index-interactive-merging-75">interactive merging</a>: <a href="#Interactive-Merging">Interactive Merging</a></li>
<li><a href="#index-introduction-2">introduction</a>: <a href="#Comparison">Comparison</a></li>
<li><a href="#index-intuiting-file-names-from-patches-100">intuiting file names from patches</a>: <a href="#Multiple-Patches">Multiple Patches</a></li>
<li><a href="#index-invoking-_0040command_007bcmp_007d-125">invoking <samp><span class="command">cmp</span></samp></a>: <a href="#Invoking-cmp">Invoking cmp</a></li>
<li><a href="#index-invoking-_0040command_007bdiff_007d-143">invoking <samp><span class="command">diff</span></samp></a>: <a href="#Invoking-diff">Invoking diff</a></li>
<li><a href="#index-invoking-_0040command_007bdiff3_007d-147">invoking <samp><span class="command">diff3</span></samp></a>: <a href="#Invoking-diff3">Invoking diff3</a></li>
<li><a href="#index-invoking-_0040command_007bpatch_007d-151">invoking <samp><span class="command">patch</span></samp></a>: <a href="#Invoking-patch">Invoking patch</a></li>
<li><a href="#index-invoking-_0040command_007bsdiff_007d-155">invoking <samp><span class="command">sdiff</span></samp></a>: <a href="#Invoking-sdiff">Invoking sdiff</a></li>
<li><a href="#index-keyboard-input-to-_0040command_007bpatch_007d-114">keyboard input to <samp><span class="command">patch</span></samp></a>: <a href="#patch-and-Keyboard-Input">patch and Keyboard Input</a></li>
<li><a href="#index-kibibyte_002c-definition-of-130">kibibyte, definition of</a>: <a href="#cmp-Options">cmp Options</a></li>
<li><a href="#index-kilobyte_002c-definition-of-129">kilobyte, definition of</a>: <a href="#cmp-Options">cmp Options</a></li>
<li><a href="#index-LC_005fCOLLATE-53"><code>LC_COLLATE</code></a>: <a href="#Comparing-Directories">Comparing Directories</a></li>
<li><a href="#index-LC_005fNUMERIC-48"><code>LC_NUMERIC</code></a>: <a href="#Line-Group-Formats">Line Group Formats</a></li>
<li><a href="#index-LC_005fTIME-21"><code>LC_TIME</code></a>: <a href="#Detailed-Context">Detailed Context</a></li>
<li><a href="#index-line-formats-49">line formats</a>: <a href="#Line-Formats">Line Formats</a></li>
<li><a href="#index-line-group-formats-46">line group formats</a>: <a href="#Line-Group-Formats">Line Group Formats</a></li>
<li><a href="#index-mebibyte_002c-definition-of-132">mebibyte, definition of</a>: <a href="#cmp-Options">cmp Options</a></li>
<li><a href="#index-megabyte_002c-definition-of-131">megabyte, definition of</a>: <a href="#cmp-Options">cmp Options</a></li>
<li><a href="#index-merge-commands-77">merge commands</a>: <a href="#Merge-Commands">Merge Commands</a></li>
<li><a href="#index-merged-_0040command_007bdiff3_007d-format-71">merged <samp><span class="command">diff3</span></samp> format</a>: <a href="#Bypassing-ed">Bypassing ed</a></li>
<li><a href="#index-merged-output-format-42">merged output format</a>: <a href="#If_002dthen_002delse">If-then-else</a></li>
<li><a href="#index-merging-from-a-common-ancestor-64">merging from a common ancestor</a>: <a href="#diff3-Merging">diff3 Merging</a></li>
<li><a href="#index-merging-interactively-78">merging interactively</a>: <a href="#Merge-Commands">Merge Commands</a></li>
<li><a href="#index-messages-from-_0040command_007bpatch_007d-111">messages from <samp><span class="command">patch</span></samp></a>: <a href="#patch-Messages">patch Messages</a></li>
<li><a href="#index-multibyte-characters-163">multibyte characters</a>: <a href="#Internationalization">Internationalization</a></li>
<li><a href="#index-multiple-patches-99">multiple patches</a>: <a href="#Multiple-Patches">Multiple Patches</a></li>
<li><a href="#index-newline-treatment-by-_0040command_007bdiff_007d-52">newline treatment by <samp><span class="command">diff</span></samp></a>: <a href="#Incomplete-Lines">Incomplete Lines</a></li>
<li><a href="#index-normal-output-format-17">normal output format</a>: <a href="#Normal">Normal</a></li>
<li><a href="#index-options-for-_0040command_007bcmp_007d-128">options for <samp><span class="command">cmp</span></samp></a>: <a href="#cmp-Options">cmp Options</a></li>
<li><a href="#index-options-for-_0040command_007bdiff_007d-146">options for <samp><span class="command">diff</span></samp></a>: <a href="#diff-Options">diff Options</a></li>
<li><a href="#index-options-for-_0040command_007bdiff3_007d-150">options for <samp><span class="command">diff3</span></samp></a>: <a href="#diff3-Options">diff3 Options</a></li>
<li><a href="#index-options-for-_0040command_007bpatch_007d-154">options for <samp><span class="command">patch</span></samp></a>: <a href="#patch-Options">patch Options</a></li>
<li><a href="#index-options-for-_0040command_007bsdiff_007d-158">options for <samp><span class="command">sdiff</span></samp></a>: <a href="#sdiff-Options">sdiff Options</a></li>
<li><a href="#index-output-formats-13">output formats</a>: <a href="#Output-Formats">Output Formats</a></li>
<li><a href="#index-overlap-66">overlap</a>: <a href="#diff3-Merging">diff3 Merging</a></li>
<li><a href="#index-overlapping-change_002c-selection-of-67">overlapping change, selection of</a>: <a href="#Which-Changes">Which Changes</a></li>
<li><a href="#index-overview-of-_0040command_007bdiff_007d-and-_0040command_007bpatch_007d-1">overview of <samp><span class="command">diff</span></samp> and <samp><span class="command">patch</span></samp></a>: <a href="#Overview">Overview</a></li>
<li><a href="#index-paginating-_0040command_007bdiff_007d-output-56">paginating <samp><span class="command">diff</span></samp> output</a>: <a href="#Pagination">Pagination</a></li>
<li><a href="#index-patch-consumer-tips-121">patch consumer tips</a>: <a href="#Tips-for-Patch-Consumers">Tips for Patch Consumers</a></li>
<li><a href="#index-g_t_0040command_007bpatch_007d-input-format-80"><samp><span class="command">patch</span></samp> input format</a>: <a href="#patch-Input">patch Input</a></li>
<li><a href="#index-g_t_0040command_007bpatch_007d-invocation-152"><samp><span class="command">patch</span></samp> invocation</a>: <a href="#Invoking-patch">Invoking patch</a></li>
<li><a href="#index-g_t_0040command_007bpatch_007d-messages-and-questions-109"><samp><span class="command">patch</span></samp> messages and questions</a>: <a href="#patch-Messages">patch Messages</a></li>
<li><a href="#index-g_t_0040command_007bpatch_007d-options-153"><samp><span class="command">patch</span></samp> options</a>: <a href="#patch-Options">patch Options</a></li>
<li><a href="#index-patch-producer-tips-120">patch producer tips</a>: <a href="#Tips-for-Patch-Producers">Tips for Patch Producers</a></li>
<li><a href="#index-patch_002c-common-mistakes-123">patch, common mistakes</a>: <a href="#Avoiding-Common-Mistakes">Avoiding Common Mistakes</a></li>
<li><a href="#index-PATCH_005fGET-86"><code>PATCH_GET</code></a>: <a href="#Revision-Control">Revision Control</a></li>
<li><a href="#index-PATCH_005fVERSION_005fCONTROL-106"><code>PATCH_VERSION_CONTROL</code></a>: <a href="#Backup-Names">Backup Names</a></li>
<li><a href="#index-patches_002c-shrinking-124">patches, shrinking</a>: <a href="#Generating-Smaller-Patches">Generating Smaller Patches</a></li>
<li><a href="#index-patching-directories-102">patching directories</a>: <a href="#patch-Directories">patch Directories</a></li>
<li><a href="#index-pebibyte_002c-definition-of-138">pebibyte, definition of</a>: <a href="#cmp-Options">cmp Options</a></li>
<li><a href="#index-performance-of-_0040command_007bdiff_007d-57">performance of <samp><span class="command">diff</span></samp></a>: <a href="#diff-Performance">diff Performance</a></li>
<li><a href="#index-petabyte_002c-definition-of-137">petabyte, definition of</a>: <a href="#cmp-Options">cmp Options</a></li>
<li><a href="#index-g_t_0040sc_007bposix_007d-159"><span class="sc">posix</span></a>: <a href="#Standards-conformance">Standards conformance</a></li>
<li><a href="#index-g_t_0040sc_007bposix_007d-117"><span class="sc">posix</span></a>: <a href="#patch-and-POSIX">patch and POSIX</a></li>
<li><a href="#index-POSIXLY_005fCORRECT-160"><code>POSIXLY_CORRECT</code></a>: <a href="#Standards-conformance">Standards conformance</a></li>
<li><a href="#index-POSIXLY_005fCORRECT-118"><code>POSIXLY_CORRECT</code></a>: <a href="#patch-and-POSIX">patch and POSIX</a></li>
<li><a href="#index-projects-for-directories-162">projects for directories</a>: <a href="#Shortcomings">Shortcomings</a></li>
<li><a href="#index-quoting-style-115">quoting style</a>: <a href="#patch-Quoting-Style">patch Quoting Style</a></li>
<li><a href="#index-QUOTING_005fSTYLE-116"><code>QUOTING_STYLE</code></a>: <a href="#patch-Quoting-Style">patch Quoting Style</a></li>
<li><a href="#index-g_t_0040sc_007brcs_007d-83"><span class="sc">rcs</span></a>: <a href="#Revision-Control">Revision Control</a></li>
<li><a href="#index-g_t_0040sc_007brcs_007d-script-output-format-41"><span class="sc">rcs</span> script output format</a>: <a href="#RCS">RCS</a></li>
<li><a href="#index-regular-expression-matching-headings-29">regular expression matching headings</a>: <a href="#Specified-Headings">Specified Headings</a></li>
<li><a href="#index-regular-expression-suppression-8">regular expression suppression</a>: <a href="#Specified-Folding">Specified Folding</a></li>
<li><a href="#index-reject-file-names-108">reject file names</a>: <a href="#Reject-Names">Reject Names</a></li>
<li><a href="#index-removing-empty-files-97">removing empty files</a>: <a href="#Creating-and-Removing">Creating and Removing</a></li>
<li><a href="#index-reporting-bugs-169">reporting bugs</a>: <a href="#Bugs">Bugs</a></li>
<li><a href="#index-reversed-patches-90">reversed patches</a>: <a href="#Reversed-Patches">Reversed Patches</a></li>
<li><a href="#index-revision-control-81">revision control</a>: <a href="#Revision-Control">Revision Control</a></li>
<li><a href="#index-sample-input-for-_0040command_007bdiff_007d-16">sample input for <samp><span class="command">diff</span></samp></a>: <a href="#Sample-diff-Input">Sample diff Input</a></li>
<li><a href="#index-sample-input-for-_0040command_007bdiff3_007d-61">sample input for <samp><span class="command">diff3</span></samp></a>: <a href="#Sample-diff3-Input">Sample diff3 Input</a></li>
<li><a href="#index-g_t_0040sc_007bsccs_007d-85"><span class="sc">sccs</span></a>: <a href="#Revision-Control">Revision Control</a></li>
<li><a href="#index-script-output-formats-38">script output formats</a>: <a href="#Scripts">Scripts</a></li>
<li><a href="#index-g_t_0040command_007bsdiff_007d-invocation-156"><samp><span class="command">sdiff</span></samp> invocation</a>: <a href="#Invoking-sdiff">Invoking sdiff</a></li>
<li><a href="#index-g_t_0040command_007bsdiff_007d-options-157"><samp><span class="command">sdiff</span></samp> options</a>: <a href="#sdiff-Options">sdiff Options</a></li>
<li><a href="#index-g_t_0040command_007bsdiff_007d-output-format-76"><samp><span class="command">sdiff</span></samp> output format</a>: <a href="#sdiff-Option-Summary">sdiff Option Summary</a></li>
<li><a href="#index-section-headings-27">section headings</a>: <a href="#Sections">Sections</a></li>
<li><a href="#index-side-by-side-34">side by side</a>: <a href="#Side-by-Side">Side by Side</a></li>
<li><a href="#index-side-by-side-format-37">side by side format</a>: <a href="#Side-by-Side-Format">Side by Side Format</a></li>
<li><a href="#index-SIMPLE_005fBACKUP_005fSUFFIX-105"><code>SIMPLE_BACKUP_SUFFIX</code></a>: <a href="#Backup-Names">Backup Names</a></li>
<li><a href="#index-special-files-166">special files</a>: <a href="#Special-Files">Special Files</a></li>
<li><a href="#index-specified-headings-28">specified headings</a>: <a href="#Specified-Headings">Specified Headings</a></li>
<li><a href="#index-summarizing-which-files-differ-9">summarizing which files differ</a>: <a href="#Brief">Brief</a></li>
<li><a href="#index-System-V-_0040command_007bdiff3_007d-compatibility-73">System V <samp><span class="command">diff3</span></samp> compatibility</a>: <a href="#Saving-the-Changed-File">Saving the Changed File</a></li>
<li><a href="#index-tab-and-blank-difference-suppression-5">tab and blank difference suppression</a>: <a href="#White-Space">White Space</a></li>
<li><a href="#index-tab-stop-alignment-54">tab stop alignment</a>: <a href="#Tabs">Tabs</a></li>
<li><a href="#index-tebibyte_002c-definition-of-136">tebibyte, definition of</a>: <a href="#cmp-Options">cmp Options</a></li>
<li><a href="#index-terabyte_002c-definition-of-135">terabyte, definition of</a>: <a href="#cmp-Options">cmp Options</a></li>
<li><a href="#index-testing-_0040command_007bpatch_007d-93">testing <samp><span class="command">patch</span></samp></a>: <a href="#Dry-Runs">Dry Runs</a></li>
<li><a href="#index-text-versus-binary-diff-12">text versus binary diff</a>: <a href="#Binary">Binary</a></li>
<li><a href="#index-time-stamp-format_002c-context-diffs-22">time stamp format, context diffs</a>: <a href="#Detailed-Context">Detailed Context</a></li>
<li><a href="#index-time-stamp-format_002c-unified-diffs-25">time stamp format, unified diffs</a>: <a href="#Detailed-Unified">Detailed Unified</a></li>
<li><a href="#index-time-stamps-on-patched-files-98">time stamps on patched files</a>: <a href="#Patching-Time-Stamps">Patching Time Stamps</a></li>
<li><a href="#index-traditional-_0040command_007bpatch_007d-119">traditional <samp><span class="command">patch</span></samp></a>: <a href="#patch-and-Tradition">patch and Tradition</a></li>
<li><a href="#index-two_002dcolumn-output-35">two-column output</a>: <a href="#Side-by-Side">Side by Side</a></li>
<li><a href="#index-unified-output-format-23">unified output format</a>: <a href="#Unified-Format">Unified Format</a></li>
<li><a href="#index-unmerged-change-68">unmerged change</a>: <a href="#Which-Changes">Which Changes</a></li>
<li><a href="#index-varying_002dwidth-characters-164">varying-width characters</a>: <a href="#Internationalization">Internationalization</a></li>
<li><a href="#index-verbose-messages-from-_0040command_007bpatch_007d-112">verbose messages from <samp><span class="command">patch</span></samp></a>: <a href="#More-or-Fewer-Messages">More or Fewer Messages</a></li>
<li><a href="#index-version-control-82">version control</a>: <a href="#Revision-Control">Revision Control</a></li>
<li><a href="#index-VERSION_005fCONTROL-107"><code>VERSION_CONTROL</code></a>: <a href="#Backup-Names">Backup Names</a></li>
<li><a href="#index-VERSION_005fCONTROL-87"><code>VERSION_CONTROL</code></a>: <a href="#Revision-Control">Revision Control</a></li>
<li><a href="#index-white-space-in-patches-89">white space in patches</a>: <a href="#Changed-White-Space">Changed White Space</a></li>
<li><a href="#index-yottabyte_002c-definition-of-142">yottabyte, definition of</a>: <a href="#cmp-Options">cmp Options</a></li>
<li><a href="#index-zettabyte_002c-definition-of-141">zettabyte, definition of</a>: <a href="#cmp-Options">cmp Options</a></li>
   </ul><div class="footnote">
<hr>
<a name="texinfo-footnotes-in-document"></a><h4>Footnotes</h4><p class="footnote"><small>[<a name="fn-1" href="#fnd-1">1</a>]</small> A coding error in <span class="sc">gnu</span> <samp><span class="command">patch</span></samp> version
2.5.4 causes it to always use `<samp><span class="samp">~</span></samp>', but this should be fixed in
the next release.</p>

   <p><hr></div>

</body></html>

